I have a Contact Activity which is derived from ListActivity, which displays list of contacts, and on click of item, a new Activity Message Activity derived from ListActivity is initialized.
Now I know, I can pack some information in Bundle and pass it before creating activity, but is there a way I can get instance of "ContactActivity" in onCreate method of "MessageActivity"?
Start the Second Activity To start an activity, call startActivity() and pass it your Intent . The system receives this call and starts an instance of the Activity specified by the Intent .
If you start the activity with startActivityForResult(Intent, int) , then you can get calling activity by getCallingActivity(). getClassName() .
Activity instances are always created by the Android system. This is because a lot of initializations have to be done for the activity to work. To create a new activity you call startActivity with an Intent describing the activity to start.
startActivityForResult(Intent intent,int requestCode) will give the response from second activity to first activity as a result.
Yes there is, you can do a workaround. In your message Activity declare a static attribute of the type of your contact class, then you set that attribute with the selected contact when the list is clicked and then you start your message activity. When onCreate is executed in your message activity you can use that attribute.
No, sorry, there is no built-in means for you to get at the activity that called startActivity()
for your current activity. After all, the original activity might not be in your application (e.g., home screen).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With