Android App Starting Multiple Times

I noticed that when I ran WebcomiX on Android, backgrounded it and then came back to it later, sometimes the Faves screen would be blank and sometimes  it would appear to go through the whole launch procedure. I just assumed it had been unloaded from memory and was just starting up again.Then one day while debugging it, I noticed that the bringing it to the foreground actually caused the app to “start again” in the same debug session.

06-23 16:45:48.371 D/Mono    ( 5289): Assembly Ref addref System.Xml[0x6f160fe980] -> mscorlib[0x6f43026e00]: 51
Loaded assembly: System.Xml.dll [External]
[0:] MainActivity.OnCreate.
[0:] App started
[0:] MainPage.MainPage.
[0:] FavesPage.FavesPage.
[0:] LibraryPage.libraryPage.
[0:] ListView: GroupHeaderTemplate and GroupDisplayBinding can not be set at the same time, setting GroupDisplayBinding to null
[0:] AboutPage.AboutPage....
06-24 17:27:55.156 D/InputTransport( 9430): Input channel destroyed: fd=147
06-24 17:27:55.157 I/Choreographer( 9430): Skipped 36 frames! The application may be doing too much work on its main thread.
06-24 17:27:58.307 W/ActivityThread( 9430): handleWindowVisibility: no activity for token android.os.BinderProxy@a60629a
[0:] MainActivity.OnCreate.
06-24 17:27:58.420 D/InputTransport( 9430): Input channel constructed: fd=159
06-24 17:27:58.420 D/ViewRootImpl@870dd16[SplashActivity]( 9430): setView = DecorView@6f0697[SplashActivity] TM=true MM=false
06-24 17:27:58.436 D/ViewRootImpl@870dd16[SplashActivity]( 9430): dispatchAttachedToWindow
06-24 17:27:58.444 D/ViewRootImpl@870dd16[SplashActivity]( 9430): Relayout returned: old=[0,0][1080,2220] new=[0,0][1080,2220] result=0x1 surface={valid=false 0} changed=false
06-24 17:27:58.445 E/ViewRootImpl@870dd16[SplashActivity]( 9430): Surface is not valid.
06-24 17:27:58.445 W/ActivityThread( 9430): handleWindowVisibility: no activity for token android.os.BinderProxy@3120084
[0:] MainActivity.OnCreate.
[0:] App started
[0:] MainPage.MainPage.
[0:] FavesPage.FavesPage.
[0:] LibraryPage.libraryPage.
[0:] ListView: GroupHeaderTemplate and GroupDisplayBinding can not be set at the same time, setting GroupDisplayBinding to null
[0:] AboutPage.AboutPage.

This is the log file form one single debug session.  I have logging in all my constructors and as you can see, the App constructor was called once at the beginning of the app and then once later on.  Now, I am not sure what is going on here.  The data from the initial run of the app stills seems to be around.  In the latter case, I set a flag to say I have done my initial load and when it “starts” for the second time, it skips the whole “data load procedure” and carries on from where it left off.  I think in the former case some of my view model constructors were being run again and that was clearing some collections.

I posted this on the Xamarin.Forms forum and someone said this was a kown issue with Android apps and was to to with the way Activities are handled and OnCreate being called multiple times.  Hopefully Forms 4 will fix it.  But that is another post.

Update

By the look of it, you can’t guarantee that the data from the last”start” is still valid.  I have had instances where it has restarted and given errors when you try and click on something.  The UI is still bound to some data  but when you click on a comic you get a “key not found in dictionary error”, as if one of the main collections has been wiped.

Join the Conversation

1 Comment

Leave a comment

Your email address will not be published. Required fields are marked *