0

Hi Everyone im developing one android application in which there are 7 screens. when i debug my application it works fine and when i click on home button at 4 screen and again i start my app it starts from same screen/4screen where the app goes into background,but when i create app.apk file for my users and when they use that app and press home key suppose at 4 screen and he/she restart the app starts from starting screen that is login screen/1 screen . Can any buddy tell me whats the problem in it and what can i do to sortout this problem.

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.dblist);
    setTitle("Databases");

    try {
        jsonObj = new JSONObject(getIntent().getStringExtra("key"));
        nameArray = jsonObj.names();
        valArray = jsonObj.getJSONArray("DbList");
    } catch (JSONException e1) {

        e1.printStackTrace();
    }

    ArrayAdapter<String> dbName = new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_1);

    for (Integer i = 0; i < valArray.length(); i++) {

        try {
            String obj = valArray.getJSONObject(i)
                    .getString("DataBaseName").toString();
            dbName.add(obj);
        } catch (JSONException e) {

        }

    }
    setListAdapter(dbName);
}


@Override
protected void onResume() {

    super.onResume();

    // versionUpdate();

    Logout lo = new Logout();
    lo.Check();
    processThreadLogoutTime();

}

final Handler handler = new Handler() {

    @Override
    public void handleMessage(Message msg) {

        super.handleMessage(msg);

        int compareTime = 1;

        if (diff >= compareTime) {

            Intent intent = new Intent(ShowDbList.this, LoginActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);

        }

    }

};

protected void processThreadLogoutTime() {

    new Thread() {

        public void run() {

            cw = new ConnectToWebService();
            getMethod gm = getMethod.GetApplicationDetails;
            String result = cw.getUrl("", gm);
            String urlLogoutTime = result.replaceAll(" ", "%20");
            cw.LogoutTime(urlLogoutTime);
            Logout logout = new Logout();

            diff = logout.LogoutFun();

            handler.sendEmptyMessage(0);

        }

    }.start();

}

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {

    String item = (String) getListAdapter().getItem(position);
    Entities.DataBaseName = item;
    try {
        String webAdmin = valArray.getJSONObject(position)
                .getString("WebAdmin").toString();
        Integer uId = Integer.parseInt(valArray.getJSONObject(position)
                .getString("UserID"));
        Entities.webAdmin = webAdmin;
        Entities.userId = uId;
    } catch (JSONException e) {
        // TODO Auto-generated catch block

    }
    Intent intent = new Intent(v.getContext(), Menu.class);
    startActivity(intent);

}
Sachin Gurnani
  • 2,444
  • 7
  • 36
  • 45
  • 2
    Your application gets killed for the users,so when they start the application again,it restarts. But when you test it on your emulator it may not be getting killed, hence it resumes from where it left. And really, you can't help it, Android kills application when there is requirement(like memory). – Kazekage Gaara May 15 '12 at 06:14
  • 1
    Are you using finish() when you are moving from one activity to another or please share the code for activity 4. – Roll no1 May 15 '12 at 06:14
  • im not getting any error but when i click on Home Key app starts from login screen. i want app starts from same screen from where it goes into the background. – Sachin Gurnani May 15 '12 at 06:20
  • @Kazekage Gaara But is there any way to do it and one more thing before this im not facing any problem like this it works as user expected – Sachin Gurnani May 15 '12 at 06:24
  • @Roll no1 no im not using finish() when im moving from one activity to another – Sachin Gurnani May 15 '12 at 06:26
  • Hey guys...I have same problem...any solution ? – Ketan Ahir Dec 01 '12 at 07:55
  • @kettu i posted the answer below please use this code it solves your problem – Sachin Gurnani Dec 01 '12 at 08:26

1 Answers1

0

Kazekage Gaara is right: Your application gets killed. If you insist on starting the application from where it where last, even if it has been closed, you need to handle this. Make a persistent save of the state whenever onStop is called and make sure that the user is sent to the correct place in onCreate/onStart.

Warpzit
  • 27,966
  • 19
  • 103
  • 155