-1

My app has 40 activities..i need to start the application from the activity where user closed last time(if i closed my app from "update profile" activity..next time when i open the app it should open "Update Profile" not From "Main Activity")..i can do it by using SharedPreferences. But i have too many activities to handle..so its little bit confusion..Is there any alternative solution for this..
Thank you all.. [I Refer this link to do by SharedPreferences]

How to make an android app return to the last open activity when relaunched?.

Prasanth Yejje
  • 267
  • 1
  • 3
  • 10
  • you can define a static integer variable for each and every activity like 0,1,2 etc. Once onCreate of each activity you can save the respective number in shared preference. Next time closing and opening the app in splash activity you compare the saved preference with the respective pre defined values and migrate to that activity directly. – Rameshbabu Jun 20 '17 at 11:19
  • Answer in the link u provided is pretty straight forward whats the issue u r facing?? – Moulesh Jun 20 '17 at 11:21
  • I don't want to use SharedPreferences..because i have more than 40 activities in my App. – Prasanth Yejje Jun 20 '17 at 11:29

2 Answers2

0

try this way create one class of sharedprefrence like this

    public class PrefManager {
    SharedPreferences pref;
    SharedPreferences.Editor editor;
    Context context;
    public  final String NAME = "name";

    // shared pref mode
    int PRIVATE_MODE = 0;

  public PrefManager(Context context) {
        this.context = context;
    pref = context.getSharedPreferences(NAME, PRIVATE_MODE);
        editor = pref.edit();}

 public void setName(String actName) {
        editor.putInt(NAME, actName);
        editor.commit();
    }

    public String getGetName() {
        return pref.getString(NAME, "deafult");
    }

   }

now when your have to save your activity than just this method like this;

 PrefManager  prefFilter = new PrefManager(this);

 //    to set data use this
 prefFilter.setName("your activity Name");

 // to retrive data user this
PrefManager  prefFilter = new PrefManager(this);
String name =prefFilter.getName();
AskNilesh
  • 67,701
  • 16
  • 123
  • 163
0

You can use android:alwaysRetainTaskState. Declare this to true in your root/main activity declaration in manifest file.

siva
  • 1,850
  • 13
  • 14