Reputation: 8717
This is a very basic question, I have a few screens, now when you go from one to another you can then press back and cycle back through all the windows.
I'd rather that when you pressed back it took you to a specific window for instance:
Now is this to do with the hierarchical parent, will this define where it goes back to?
The second part of my question is if I don't have any resources to release or information to store for an on-resume what should I do when the user pauses my app? At the moment if you go back to the menu screen and re-select the app it will start a new instance rather than resuming. Do I just simply implement:
@Override
public void onPause() {
super.onPause(); // Always call the superclass method first
}
and
@Override
public void onResume() {
super.onResume(); // Always call the superclass method first
}
Apologies if this is a bit basic!
Upvotes: 0
Views: 318
Reputation: 3408
For your two parts:
1) It's almost always best to let Android handle the back button, the order of which is determined by the back stack: see here for an explanation. If you want hierarchical navigation, I would recommend looking into the up
button - see this developer page for a good explanation of how to use the different navigation tools.
Additionally, if you don't want to have an activity appear in your back stack, you can set the attribute android:noHistory="true"
in your manifest, which will mean that the user can't return to it using the back button.
2) If the user has left your app, it's automatically paused, you don't need to implement onPause
or onResume
for this to happen. However, it's also up for collection to be terminated by the OS. If this happens, then it will be restarted when the user opens it from the launcher again. Any previously running instances of the app should automatically be opened.
Upvotes: 1
Reputation: 854
You might want to look in to setting FLAGS for your intent while opening new activity Android Dev
Something like this -
Intent a = new Intent(this,A.class);
a.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(a);
Upvotes: 1
Reputation: 1174
There is no basic questions here :)
Easiest way to do this is to override the onBackPress() function.
Sample :
@Override public void onBackPressed() { //Do what you want here }
For saving variables when users leave the app, you need to override onSaveInstanceState(Bundle bundle)
@Override protected void onSaveInstanceState(Bundle bundle) { super.onSaveInstanceState(outState); bundle.putInt("sample", 1); }
Upvotes: 1