Issue
I have the following Activity:
public class StartActivity extends Activity
{
String str = "somestring";
int number = "1";
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Code here
}
}
I read the following on the Android docs (http://developer.android.com/reference/android/app/Activity.html)
If an activity is completely obscured by another activity, it is stopped. It still retains all state and member information, however, it is no longer visible to the user so its window is hidden and it will often be killed by the system when memory is needed elsewhere.
Does this mean that my class instances (str and number) are "alive" and available unless onDestroy is called or memory is needed after onPause or onStop is called?
Solution
If in your caller activity, you have called finish()
method, then no instances of previous activity will be alive since you have finished caller activity. All the instances will be garbage collected.
But if your caller activity, does not call finish()
, then the activity will no longer be visible but, it will be present on the activity stack maintained by the operating system. The caller activity (i.e. the previous activity) may get finished in cases when the device is low in memory like in cases, ex.: if the activity calls Camera (which requires rich resources), in that case the previous activity may get destroyed.
So in your case, the variables will be alive even if StartActivity
is not the present visible activity.
Answered By - Shrikant Ballal
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.