5

My app has 3 classes. First class is a splash screen, second class contains a list of playlists and third class that playlist's content. When a playlist is selected that third class get started to show the playlist content. On second class I have :

@Override
    protected void onStop() {
        super.onStop();
        System.out.println("onStop Playlist!!!!");
    }

    protected void onDestroy() {
        super.onDestroy();
        System.out.println("onDestroy Playlist");
    }

and when third class is ready to start, I get on DDMS the messages :"onStop Playlist!!!!" and "onDestroy Playlist". Why are this method called? Shouldn't be called only onPause method? The problem is that I want to stop some timer when app is finishing, but I don't know in this case where can I stop the timer. Any idea?

I call the third class like this :

Intent i = new Intent(getBaseContext(), ViewPlaylist.class);
i.putExtra("id", idPlaylist[position]);
i.putExtra("timer", timerPlaylist[position]);
startActivity(i);
finish();

The problem is that I call finish() ?

Gabrielle
  • 4,933
  • 13
  • 62
  • 122
  • Its depends on How you called the Third class(start third activity). If you display some code then we can help you. – user370305 Nov 24 '11 at 09:13

3 Answers3

5

If you read the docs for the Activity class(for the onDestroy() method) will see that :

The final call you receive before your activity is destroyed. This can happen either because the activity is finishing (someone called finish() on it, or because the system is temporarily destroying this instance of the activity to save space. You can distinguish between these two scenarios with the isFinishing() method.

user
  • 86,916
  • 18
  • 197
  • 190
1

Its because you are finishing the second activity with finish(). so instead of use startActivityForResult() and override onActivityResult() in second activity, So in this case your second activity's onPause() will be called, and when you finish() third activity you can back to your second activity's onActivityResult() method()

Try this code...

Intent i = new Intent(getBaseContext(), ViewPlaylist.class);
i.putExtra("id", idPlaylist[position]);
i.putExtra("timer", timerPlaylist[position]);
startActivityForResult(i,RESULT_OK);
user370305
  • 108,599
  • 23
  • 164
  • 151
0

Yes, you call finish(). This will finish, thus destroy that activity. Just remove the finish() call. It's only needed if you want to destroy a activity.

Peterdk
  • 15,625
  • 20
  • 101
  • 140
  • at another project, everytime I started a new activity I called finish() I that solved the error OOM – Gabrielle Nov 24 '11 at 09:38
  • I removed finish() but onStop is still called... why? – Gabrielle Nov 24 '11 at 09:39
  • @Gabrielle `onStop()` is called because your activity is no longer visible to the user, the class with the playlist content covers it. This is a normal life cycle flow for and android app. In my answer i put a link where you can read more about how this life cycle methods are called and when they are called. – user Nov 24 '11 at 11:38