MvvmCross / MvvmCross-Forms

Support for Xamarin.Forms on MvvmCross: The .NET MVVM framework for cross-platform solutions, including Xamarin.iOS, Xamarin.Android, Windows and Mac.
http://mvvmcross.com
6 stars 2 forks source link

issue on Android when click Back button #12

Closed flashvnn closed 9 years ago

flashvnn commented 9 years ago

I got issue when using MvvmCross-Forms for Android app, when click back button it close app, but when i open app again, then click back button it don't close app correctly. Please check video issue here: https://youtu.be/N8PvlO54dK0

PeterBurke commented 9 years ago

Hi Flashvnn

Thanks for the video, I will look into it.

Are you using the very latest release? It looks like the previous release to me. For Android there is a Flash screen that simply reads MvvMCross. I see that in your video, but I do not see the first page that has some labels and a TextEntry.

Also I presume that the Back Button should attempt to navigate back to the previous page or shut down the App.

In Android the App does not necessarily shut down though. It also depends on the version of Android. You may be aware that originally Android was based on converting Java bytecodes into a different format called Dalvik. This format still required an interpretor to run. Now on KitKat Google released ART (Android Run Time) basically a situation where Dalvik is compiled into machine code Ahead Of Time, in fact during App installation. ART became mandatory in Lollipop released November last year.

ART keeps the Apps in memory even when you have hit that back button to speed up reopening. Only when it needs the memory will it completely go.

Now this is a potential issue for the Example.Droid because in that version there is no real navigation in place. In the current release there should be one navigation from the splash screen to the FirstPage but nothing more. I will release a new PR shortly that will demonstrate navigation to an About page and back. At that time I will test the use of the back button like in your video and make sure it works.

Thanks for your help.

flashvnn commented 9 years ago

Hi PeterBurke, i upload new video demo app build with lasted source code here: https://www.youtube.com/watch?v=EGqCzjZsD5M issue still available. i make some debug and see that after first time close (but app don't shut down) then click open app again it push new FirstPage to navigation so in navigation have 2 page FirstPage but i still not found way to fix it, looking for you help.

thanks.

flashvnn commented 9 years ago

I found the way to solved my problem by edit code for InitializationComplete function in SplashScreen class. Not sure is it the correct way but it work.

        private bool isInitializationComplete = false;
        public override void InitializationComplete()
        {
            if (!isInitializationComplete) {
                isInitializationComplete = true;
                StartActivity(typeof(MvxFormsApplicationActivity));
            }
        }
PeterBurke commented 9 years ago

That is awesome Huynh!

I will incorporate it into the next Pull request.

Come again!