I have a main activity and a sub activity. The main activity starts the sub activity using startActivity, and passes an object in the intent. The sub activity reads the object out of the intent in its onCreate action. The sub activity updates the object, then returns to the main activity using startActivity, again passing the updated object back. However, the main activities onCreate function is not called, so the code it contains to read the passed object does not run.
Further investigation indicated that the main activity onPause event is firing, i.e. it is only paused when the sub activity runs, so when the sub activity starts the main activity again, it just onResumes.
Does anyone know if there would be any disadvantages if I moved my data restore/store activities to the onResume and onPause events? I'm not using the onCreate savedInstanceState, should I be?
How else do you pass a set of data items between Activities without using a database or those preferences? Should I be using a database? I have about 20 fairly individual data items.
Any help would be much appreciated,
Q 9 – What is the purpose of super. onCreate() in android? The super. onCreate() will create the graphical window for subclasses and place at onCreate() method.
As per official documentation: You can call finish() from within this function, in which case onDestroy() will be immediately called after onCreate(Bundle) without any of the rest of the activity lifecycle (onStart(), onResume(), onPause(), etc) executing.
Starting activities or services. To start an activity, use the method startActivity(intent) . This method is defined on the Context object which Activity extends. The following code demonstrates how you can start another activity via an intent.
By the help of android startActivityForResult() method, we can send information from one activity to another and vice-versa. The android startActivityForResult method, requires a result from the second activity (activity to be invoked).
Whether an activity is the main activity that's created when the user clicks your app icon or a different activity that your app starts in response to a user action, the system creates every new instance of Activity by calling its onCreate () method.
You can use startActivtyForResult method to start the activty2 then when onActivityResult of activty1 called call setContentView for the first one Show activity on this post.
If you run the app and tap the button on the first activity, the second activity starts but is empty. This is because the second activity uses the empty layout provided by the template. Figure 1.
The Intent constructor takes two parameters, a Context and a Class. The Context parameter is used first because the Activity class is a subclass of Context. The Class parameter of the app component, to which the system delivers the Intent, is, in this case, the activity to start.
I would check out the startActivityForResult()
method rather than just startActivity()
That should give you a means to pass things back to the calling activity.
From http://developer.android.com/reference/android/app/Activity.html:
Sometimes you want to get a result back from an activity when it ends. For example, you may start an activity that lets the user pick a person in a list of contacts; when it ends, it returns the person that was selected. To do this, you call the startActivityForResult(Intent, int) version with a second integer parameter identifying the call. The result will come back through your onActivityResult(int, int, Intent) method.
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