Android programming realizes the method of sharing data and accessing each other between two activities

This paper describes the method of sharing data and accessing each other between two activities by Android programming. Share with you for your reference, as follows:

I switched from windows programming to Android development. I always thought that if two activities can directly access their members (characters, values, member objects, etc.) and call their public methods like the form in c# or Delphi, it should be much more convenient than using intent to transfer data directly. Therefore, I tried the following methods. There is basically no problem in the test, Send it out for discussion. I learned Android soon. I hope you don't laugh at childish places

Principle: suppose there are two activities: activitymain and activityNew. Start activityNew in activitymain, and in activityNew, you can access the member object in activitymain and call its exposed methods. First, define a static member variable in activitymain of type activitymain, and then assign this instance of activitymain to the member in the oncreate process:

To access member variables and methods in activitymain in activityNew:

I hope this article will help you in Android programming.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>