Should startActivity always start running onCreate actions?

I have a main action and sub-activity. The main action starts the sub-activity using startActivity and passes the object to the intent. Sub-activity reads an object from an intent in its onCreate action. Sub-activity updates the object, and then returns to the main action using startActivity, passing the updated object back again. However, the main functions of onCreate are not called, so the code that it contains to read the passed object does not start.

Further research showed that the main activity of the onPause event is triggered, that is, it is suspended only when the sub-activity is performed, therefore, when the auxiliary activity starts the main action again, it simply calls.

Does anyone know if there will be any flaws if I transfer my data recovery / storage operations to onResume and onPause events? I do not use onCreate savedInstanceState, should I be?

How else do you pass a set of data items between actions without using a database or these settings? Should I use a database? I have about 20 fairly separate data items.

Any help would be greatly appreciated

  • Frrink
+4
source share
4 answers

I would look at the startActivityForResult() method, not just startActivity()

This should give you the opportunity to transfer things to the challenge.

From http://developer.android.com/reference/android/app/Activity.html :

Sometimes you want to get a result from an action when it ends. For example, you can start an action that allows the user to select a person in the contact list; 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 that identifies the call. The result will return through your onActivityResult (int, int, Intent) method.

+6
source

Look at the life cycle of an activity here .

Also, consider starting your sub-activity using StartActivityForResult .

+1
source

Most likely, onResume () or onStart () is called depending on the child activity and how much control is required.

Look at this page about 3/4 down on the graph.

http://developer.android.com/guide/topics/fundamentals.html alt text

A parent is never destroyed, so he does not need to recreate it. He should just pause. You can override onResume () and onStart () in the same way as onCreate ().

Edit: is there anything given to the user in subactivity? It sounds like you really don't need an activity, you just need a java class that you can call methods on.

0
source

Why don't you call startActivityForResult from the main action and return the data to onActivityResult? This is a normal way to do this.

0
source

All Articles