Phantom
Phantom

Reputation: 53

Xamarin issue when the app go OnSleep using the back button

im having an issue with mi xamarin app, if my app go onSleep using the home button of the phone its resume with no problem, but if i use the back button the app stay freeze in a white screen and never hits the OnResume(), i want it to have the same behavior or at least that using the back button close the app entirely

Code

protected override void OnStart ()
    {
        // Handle when your app starts
    }
    protected override void OnResume()
    {
        base.OnResume();
        App.IsInBackgrounded = false;
    }
    protected override void OnSleep ()
    {
        // Handle when your app sleeps
        base.OnSleep();
        App.IsInBackgrounded = true;
    }

The Output when i use the home button

12-23 11:23:35.517 D/ViewRootImpl@b3d0e31[MainActivity](15966): Relayout returned: old=(0,0,1080,2340) new=(0,0,1080,2340) req=(1080,2340)4 dur=21 res=0x1 s={false 0} ch=false
12-23 11:23:35.518 D/ViewRootImpl@b3d0e31[MainActivity](15966): stopped(false) old=true
12-23 11:23:35.620 D/ViewRootImpl@b3d0e31[MainActivity](15966): stopped(false) old=false
12-23 11:23:35.705 D/ViewRootImpl@b3d0e31[MainActivity](15966): Relayout returned: old=(0,0,1080,2340) new=(0,0,1080,2340) req=(1080,2340)0 dur=28 res=0x7 s={true 530976370688} ch=true
12-23 11:23:35.705 D/OpenGLRenderer(15966): createReliableSurface : 0x7bf7e1bf80, 0x7ba0a87000
12-23 11:23:35.739 D/mali_winsys(15966): EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface, EGLConfig, egl_winsys_surface **, EGLBoolean) returns 0x3000
12-23 11:23:35.950 I/om.kuwaidev.tp(15966): Explicit concurrent copying GC freed 2262(149KB) AllocSpace objects, 0(0B) LOS objects, 49% free, 3171KB/6343KB, paused 77us total 27.240ms
12-23 11:23:35.954 D/Mono    (15966): GC_TAR_BRIDGE bridges 537 objects 25741 opaque 12967 colors 537 colors-bridged 537 colors-visible 537 xref 7 cache-hit 0 cache-semihit 0 cache-miss 0 setup 0.10ms tarjan 19.63ms scc-setup 0.18ms gather-xref 0.01ms xref-setup 0.01ms cleanup 2.11ms
12-23 11:23:35.954 D/Mono    (15966): GC_BRIDGE: Complete, was running for 34.77ms
12-23 11:23:35.954 D/Mono    (15966): GC_MINOR: (Nursery full) time 35.83ms, stw 37.16ms promoted 675K major size: 8784K in use: 7971K los size: 7168K in use: 5791K
12-23 11:23:35.983 D/ViewRootImpl@b3d0e31[MainActivity](15966): MSG_WINDOW_FOCUS_CHANGED 1 1
12-23 11:23:35.984 D/InputMethodManager(15966): prepareNavigationBarInfo() DecorView@fbe4d10[MainActivity]
12-23 11:23:35.984 D/InputMethodManager(15966): getNavigationBarColor() -11427245
12-23 11:23:36.002 D/InputMethodManager(15966): prepareNavigationBarInfo() DecorView@fbe4d10[MainActivity]
12-23 11:23:36.002 D/InputMethodManager(15966): getNavigationBarColor() -11427245
12-23 11:23:36.003 V/InputMethodManager(15966): Starting input: tba=com.kuwaidev.tpv ic=null mNaviBarColor -11427245 mIsGetNaviBarColorSuccess true , NavVisible : true , NavTrans : false
12-23 11:23:36.003 D/InputMethodManager(15966): startInputInner - Id : 0
12-23 11:23:36.003 I/InputMethodManager(15966): startInputInner - mService.startInputOrWindowGainedFocus

the output when i use the back button output

Upvotes: 0

Views: 450

Answers (1)

DevenCC
DevenCC

Reputation: 496

The Back and Home buttons act differently through the application lifecycle events. Pressing home will background the application; therefore it will pass through OnResume when launching the application again. Contrarywise, pressing Back kills the application. It will therefore pass through the OnStart when launching again.

Here is the documentation supporting.

Upvotes: 3

Related Questions