Skip to content

Bug related to the life cycle of an Android application #185

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rigor789 opened this issue Apr 17, 2018 · 14 comments
Closed

Bug related to the life cycle of an Android application #185

rigor789 opened this issue Apr 17, 2018 · 14 comments

Comments

@rigor789
Copy link
Member

From @Fabiyo-90 on April 17, 2018 18:48

I am on android, once I press the button "back" and that the application is found in pause "onPause ()", and then I click on the icon of the application to engage "surResume ()" then the application bug. Once stop "onStop ()", click on the icon while it normally starts. Bug related to the life cycle of an Android application.

Copied from original issue: nativescript-vue/nativescript-vue.org#95

@rigor789
Copy link
Member Author

@Fabiyo-90 I'm not sure if I understand you correctly, but if you are talking about the issue where if the activity gets suspended and then recreated the app is unresponsive (no events or bindings work) then yes, that's an issue that I'm currently investigating. It is an issue in NativeScript core too, so I'm not sure how to fix it yet.

@ghost
Copy link

ghost commented Apr 17, 2018

it's exactly that, I'm preparing a presentation to my friends and I would not like a bug because I'm trying to create a mobile developer community around nativescript-view. I am a student in DR Congo, French speaking country.
Else Nativescript-view is a great project especially since the framework vujs is very simple and easy to handle.
Thank you for this gift

@ghost
Copy link

ghost commented Apr 17, 2018

I pray that this bug is quickly solved

@rigor789
Copy link
Member Author

I've released an rc build which should fix the issue, can you try it and let me know if it works for you?

nativescript-vue@1.3.2-rc.2

@ghost
Copy link

ghost commented Apr 18, 2018

@ghost
Copy link

ghost commented Apr 18, 2018

With the version "nativescript-vue@1.3.2-rc.2" the application bug when launching "onCreate ()", but with this version "nativescript-vue@1.3.2-rc.1", the application does not bug anymore. I think that I will work with this version "nativescript-vue@1.3.2-rc.1"

@Tronix117
Copy link
Contributor

As a work-around, you can use

if (isAndroid) {
  application.android.on(application.AndroidApplication.activityBackPressedEvent, backEvent)
  function backEvent(args) {
    const tm = topmost()
    if (tm.backStack.length) return
    args.cancel = true

    const startMain = new android.content.Intent(android.content.Intent.ACTION_MAIN)
    startMain.addCategory(android.content.Intent.CATEGORY_HOME)
    startMain.setFlags(android.content.Intent.FLAG_ACTIVITY_NEW_TASK)

    const activity = application.android.startActivity ||
                     application.android.foregroundActivity ||
                     tm.android.currentActivity ||
                     tm.android.activity

    activity.startActivity(startMain)
  }
}

it prevents the app to suspend, and goes directly to dashboard.

@ghost
Copy link

ghost commented Apr 22, 2018

The version nativescript-vue@1.3.2-rc.2 bug when starting the application even for a "Hello world!" but trying the nativescript-vue@1.3.2-rc.1 version, there is no bug and works very well.
I am using the version nativescript@4.0.0, tns-android@4.0.1, tns-core-module@4.0.0.
tns_bug_2

@dungfv
Copy link

dungfv commented Apr 23, 2018

I also have same problem with nativescript-vue 1.3.2-rc.* (both tns-core-modules 3.4.1 or 4.0.0)

@ghost
Copy link

ghost commented Apr 24, 2018

you have to install tns-core-modules@3.4.1 with nativescript-vue@1.3.1

@championswimmer
Copy link
Contributor

I have a hacky workaround this problem

First make sure on exit event you really really exit the app

import * as application from 'tns-core-modules/application'
import {exit} from 'nativescript-exit'

/*
 * Force an exit, instead of trying to remount
 * FIXME: On upgrade to nativescript-vue 2.x this wont be necessary
 */
application.on(application.exitEvent, (args: ApplicationEventData) => {
  exit()
})

Next, to make back button work as page routing

/*
 * Go back if in a nested route. If top level route, just do what android does
 */
if (application.android) {
  application.android.on(
    AndroidApplication.activityBackPressedEvent,
    (data: AndroidActivityBackPressedEventData) => {
      if (router.currentRoute.path.split('/').length > 2) {
        router.back()
        data.cancel = true
      }
    }
  )
}

@msaelices
Copy link

msaelices commented Aug 1, 2018

@Fabiyo-90 the traceback you linked here is due to the vue-router integration, which is still experimental until 2.0.0 was finally released.

@championswimmer the second workaround you put down (the activityBackPressedEvent hack) will not be needed after merging the vue-router integration branch to master, as you can see in this commit: bce0623

BTW, this issue should be tested in the frame-and-router branch, so I will add the check-on-v2 label.

CC/ @rigor789

@msaelices
Copy link

@Fabiyo-90 I've added this sample app which tests all the Android events: 014e812

I've tested pausing and resuming the app and is still responsive, as you can see here:

screenshot_1533203254

So closing this issue. Please re-open if I missed something.

@nativescript-vue-bot
Copy link
Collaborator

We are locking this issue because it has been closed for more than 14 days.

If the issue comes up again please open a new issue with additional details.

@nativescript-vue nativescript-vue locked as resolved and limited conversation to collaborators Aug 16, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

6 participants