MvvmCross / MvvmCross

The .NET MVVM framework for cross-platform solutions, including Android, iOS, MacCatalyst, macOS, tvOS, WPF, WinUI
http://mvvmcross.com
Microsoft Public License
3.88k stars 1.31k forks source link

MvvmCross initialization after process termination #1424

Open kenkosmowski opened 8 years ago

kenkosmowski commented 8 years ago

Steps to reproduce

  1. Grap sample from https://github.com/kenkosmowski/Android-MvvmCross-RevokePermissions
  2. Deploy app on an Android M device and start it. Do not debug, because debugger stops after revoking permissions.
  3. Navigate to "Second View" and follow the steps described in the view

    Expected behavior

After enabling and disabling camera access, the process gets killed by the OS. Android restarts the topmost activity and displays the SplashScreen during Mvx initialization (and forces IMvxAppStart to run) OR it should restart the app entirely up from scratch. After initialization, FooService should be started and display the "Message received" dialog after tapping "Publish message".

Actual behavior

Android restarts the topmost activity and displays a blank view (not the SplashScreen) during Mvx initialization. IMvxAppStart isn't triggered and FooService isn't started, so it can't display the "Message received" dialog.

Configuration

Version: 4.2.3

Platform: Android

Cheesebaron commented 8 years ago

I've played around with the sample and here is what I get when testing on a Sony Xperia Z5:

  1. Start app, I see blue splash screen (added a TextView to confirm)
  2. Navigate to second Activity
  3. Go to Settings and revoke permissions
  4. Launch app from recent apps - I don't see a splash screen
  5. Second Activity is launched

This is the exact same behavior as I've seen described on StackOverflow, as you say yourself, the topmost Activity gets launched again when you start the app from recent apps, instead of the app re-launching from scratch.

Can we do anything about this? Probably...

I've tried to see if OnDestroy gets hit in the Activity. However, it does not seem like it :(

I think the only alternative is to check in OnResume when your app is re-launched and check if previously permitted permissions have been revoked. If that is the case re-launch the app on the splash screen with FLAG_ACTIVITY_CLEAR_TASK and FLAG_ACTIVITY_NEW_TASK flags set.

kenkosmowski commented 8 years ago

The problem with re-launching the app if permissions have been revoked: During "first" re-launch from recent apps you will always see a blank screen during Mvx initialization. Only after this initialization you can re-launch on the splash screen - it works, but doesn't look very nice.

nickrandolph commented 6 years ago

@kenkosmowski a couple of things: