i’ve got 2 activities. one activity questions an external db through a web service and shows the results on another activity.
what i want is that when i press the back hardware key i should get back to the first activity and when i do another request the 2nd activitystart all over again.
here’s the code of the onBackPressed() method im using but it doesnt work! i go back to the first activity which is correct but when i do another request 2 second activity starts from where i left it the first time. for example, i have page numbers at the bottom of the 2nd activity and if i press the back hardware button from page number 3 and do another request my second activity restarts from page 3 with all its data. what am i doeing wrong. Am i doing something wrong with the android lifecycle or (as im using a singleton class to do the requests to the webservice/db) am i making a mistake using the singleton? i think my mistake is more on the first point on the lifecycle.
any help would be appreciated. thanks!
@Override
public void onBackPressed() {
super.onBackPressed();
finish();
Intent intent = new Intent(this, pluto.class);
startActivity(intent);
}
The default backpress in android removes the current activity from the stack and brings onTop the previous activity.(Thats what you are looking for).
I couldn’t understand the reason why you are overriding it at the first place and also the creating a new instance of the activity
Try commenting this method alltogether to see if that works.
Edit 1
Tasks and Back Stack link