How to get a “call” of an Activity instance from a called activity?

I have a contact activity, which is obtained from ListActivity, which displays a list of contacts and on the click of an item, a new Activity Message Activity, obtained from ListActivity is initialized.

Now I know that I can pack some information in the Bundle and pass it before creating the activity, but is there a way I can get an instance of "ContactActivity" in the onCreate method of "MessageActivity"?

+5
source share
2 answers

No, I'm sorry, there are no built-in tools for you to get an activity called startActivity()for your current activity. After all, the original action may not be in your application (for example, on the main screen).

+4
source

Yes, you can do a workaround. In your message, Activity declares a static attribute of the type of your contact class, then you set this attribute with the selected contact when you click on the list, and then start your message activity. When onCreate is running in your message activity, you can use this attribute.

+5
source

All Articles