0

In Android, you can @Override onBackPressed and start a new Intent to launch an activity.

For some reason, in OnBackPressed you can start the intent just fine, and the new activity launches; but if I were to start a new intent in the default @Override onPause method, the new activity doesn't technically launch until I open my application up once again.

Is there a way to make the home button launch my 2nd activity before the app calls onPause?

Josh Beckwith
  • 1,432
  • 3
  • 20
  • 38

1 Answers1

4

What you're asking is basically:
Can i make sure the user can never ever leave my application?

The answer is no.

There are limitations, for example that you can't override Home button presses, you can't launch a new activity when the user presses the home button in any of the lifecycle callbacks (onPause, onStop, onDestroy, etc etc)

Moonbloom
  • 7,738
  • 3
  • 26
  • 38
  • I can see how malicious intent can be observed, even though I'm not trying to make sure the user can not leave the app. I'm just looking to make sure the new activity is started and backgrounded, rather than the first activity backgrounded, and the 2nd activity starting on next app open. – Josh Beckwith May 04 '17 at 15:08
  • The answer is still no, it's the same concept. You can't start a new activity when going to the background. Why do you so badly need this activity to be started in the background? Does it do anything that runs in the background? If so, it definitely shouldn't, you should use a Service (or similar) instead. Rather than trying to hack around it, you should solve the core issue of WHY you need this activity to be running in the background. – Moonbloom May 04 '17 at 15:13