0

I have 2 Activities as below:

public class MainActivity extends Activity {
    ....


    profile.login(new onCallback()) {
        @Override
        public void onResult(int result) {
            final Intent i = new Intent(MainActivity.this, DetailActivity.class);
            startActivity(i);
        }
    }

    ....

}


public class DetailActivity extends Activity {
    ....
}

Where profile.login run on a AsyncTask and callback when there is a result. Once result received, it will start the 2nd activity.

Here is the trouble steps:

  1. On MainActivity, press on the login button.
  2. Press BACK to close the App.
  3. The app is closed but after a while the 2nd activity popup and immediately follow by a force close.

I trace the life cycle event, logcat shows:

  1. MainActivity.onClickLogin
  2. DetailActivity.onCreate started.
  3. DetailActivity.onCreate ended.
  4. MainActivity.onDestroy started.
  5. MainActivity.onDestroy ended.

It is very time-dependent and only happens between "DetailActivity.onCreate ended" and the screen is not shown. Once the DetailActivity screen shown, press Back will not cause MainActivity to destroy. It just destroy the DetailActivity as expected:

  1. MainActivity.onClickLogin
  2. DetailActivity.onCreate started.
  3. DetailActivity.onCreate ended.
  4. DetailActivity.onDestroy started.
  5. DetailActivity.onDestroy ended.

My Question is:

Since DetailActivity is already created (onCreated ended) should the back key event sent to DetailActivity and cause it destroy? Why the key is sent to MainActivity?

Any idea how to counter-measure this?

The Android version I am working on is 4.0.x

akjoshi
  • 15,374
  • 13
  • 103
  • 121
Calvin
  • 3,302
  • 2
  • 32
  • 41
  • I am not able to understand your question, but can you tell,are you want to go out from Activity2 – Narendra Pal Jan 10 '13 at 10:13
  • i think you have to check the condition that if back key is pressed then not to call second activity...if back not clicked then call second activity – Mehul Ranpara Jan 10 '13 at 10:17
  • In simple words, Activity2 oncreate is done, but screen still showing Activity1, press back at this time, cause activity1 to finish.Then only Activity2 shown up. This screw up the activity stack. It only happens if you press the back fast enough when activity2 oncreate is done but the screen not shown. – Calvin Jan 10 '13 at 10:17
  • and ya you can get the back key event – Mehul Ranpara Jan 10 '13 at 10:17
  • @mehul, the back is pressed after startActivity(activity2)... it suppose to send the back to activity2. – Calvin Jan 10 '13 at 10:18
  • so, what is your actual problem ? – Mehul Ranpara Jan 10 '13 at 10:19
  • Imagine you have one MainActivity shows up a SubActivity. Press Back cause the MainActivity to finish and the SubActivity in front still there, does that sound like a problem to you? – Calvin Jan 10 '13 at 10:21
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/22507/discussion-between-mehul-ranpara-and-calvin) – Mehul Ranpara Jan 10 '13 at 10:26

1 Answers1

0

Create header and footer. set a one image and write a code on onclick listener...

Karthikeyan Karthik
  • 114
  • 1
  • 2
  • 14