Yiğit Yükselir Yiğit Yükselir - 4 months ago 19
Android Question

How Can Resume To Last Activity?

When I open the app again, my previous activity when I press the Resume button in the Main How do I go on

Main Activity

Note:Buton 500 Resume Button

super.onCreate(savedInstanceState);
ActionBar actionBar =getSupportActionBar();
actionBar.hide();
setContentView(R.layout.activity_giris);

button1= (Button) findViewById(R.id.button);
button500= (Button) findViewById(R.id.button500);


button500.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

}
});

button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Giris.this, Soru1.class);
startActivity(intent);
finish();
}
});

}


}

Quest 1

Answer

The simplest way to do this would be using Shared Preferences. You can save the name of the last activity you used in a String in Shared Preferences, load it and start the activity which you need. You can look up how to use Shared Preferences here: https://developer.android.com/training/basics/data-storage/shared-preferences.html

Also, here is the code example how that can be done:

SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE);
String activityName = getResources().getString(R.string.saved_activity);
switch (activityName) {
    case "activityA":
        //start activity A
        break;
    case "activityB":
        //start activity B
        break;
}