2

I have an activity MainActivity from where I am opening an activity TransactionActivity but the problem happening with me is why my MainActivity's onStop() method isn't getting called only onPause() is getting called. I have seen this post on SO difference-between-onpause-and-onstop, and here in answers it is written that when some part of your activity is still visible then onStop() will not gets called the only onpause will get called but for my case as MainActivity's is completely not visible why it's onStop() is not getting called ??

Is this happening because of some Activity leak or anything which is causing my Activity to stay in memory even when it is completely not visible ??

Anyone, please enlighten me what is happening here ??

My Code for calling TransactionActivity from MainActivity

Intent i = new Intent(MainActivity.this, TransactionActivity.class);
Bundle b = new Bundle();
b.putInt("trans_type", 0);
i.putExtras(b);
startActivity(i);
overridePendingTransition(0, 0);
Sudhanshu Gaur
  • 7,486
  • 9
  • 47
  • 94

3 Answers3

1

Please check your AndroidManifest.xml, Maybe you have set a transparent theme.

dragonfly
  • 1,151
  • 14
  • 35
1

Check your activity style . the item "windowContentTransitions" is true will let the

jimbray
  • 11
  • 3
0

When you call another activity from your previous one, it is placed "beneath" the new one. So once you back press, previous activity will be shown. This is default bahavior in Android.

onStop is only called when a activity is finished. So you could, for instance, call ActivityA.finish() after a startActivity(ActivityB).

Still not really sure why you need code in your onStop method. This is dangerous since system itself can call onStop if it needs to free some memory. There's probably a better way to do what you are trying to achieve.

Good luck!

Tiago Dávila
  • 346
  • 1
  • 7
  • 2
    No, onStop() gets called when activity becomes completely invisible you can see that in the post I have mentioned in my question here https://stackoverflow.com/questions/9266417/difference-between-onpause-and-onstop – Sudhanshu Gaur Aug 14 '17 at 17:36
  • For some Android 9 devices the `onStop` method is not immediately invoked when another activity is presented (previous one becomes completely invisible). Its invokation is delayed by a few seconds and occurs while the user is seeing the new activity. – JCarlosR Nov 28 '22 at 16:26