Android Question Always open last activity

Discussion in 'Android Questions' started by ducphu, Jan 29, 2015.

  1. ducphu

    ducphu Active Member Licensed User

    Hi all,

    My app has a few activities. Let say I open a child activity then press Home button to close the app, when I re-open the app, I always see my last opened activity, even if I purposely kill the app to get rid of it from the memory. What should be the problem here?
     
  2. parijs

    parijs Active Member Licensed User

    Do you have closed the activity before you went to main?
     
  3. ducphu

    ducphu Active Member Licensed User

    Which activity? I didn't close any activity. If my last opened activity is a child activity, every time I open the app I will see that child activity. Even I kill the process, it doesn't open my main activity as it should be, but it still load that child activity.
     
  4. klaus

    klaus Expert Licensed User

    Can you post a small project showing the problem.
     
  5. ducphu

    ducphu Active Member Licensed User

    Hi klaus,

    It's difficult. My app is a large project and if I don't know where the problem is. If I make a simple project, I'm unable to generate the problem.
    Anyway, I notice that, if I force stop the app, it will load back my main activity. Does it make any clue?
     
  6. ducphu

    ducphu Active Member Licensed User

    Below is the log:
    ** Activity (main) Create, isFirst = true **
    ** Activity (main) Resume **
    ** Service (update) Create **
    ** Service (update) Start **
    ** Activity (main) Pause, UserClosed = false **
    ** Activity (activity2) Create, isFirst = true **
    ** Activity (activity2) Resume **
    ** Activity (activity2) Pause, UserClosed = false ** 'Close App by pressing Home button

    ' Manually kill the process, then open app again

    ** Activity (activity2) Create, isFirst = true **
    ** Activity (activity2) Resume **
    ** Activity (activity2) Pause, UserClosed = false **
     
  7. ducphu

    ducphu Active Member Licensed User

    Hi klaus,

    I just use the Two Activities example (http://www.b4x.com/android/forum/threads/two-activities-example.6611) to test and it happens exactly the same as my app. the log is:

    ** Activity (main) Create, isFirst = true **
    ** Activity (main) Resume **
    ** Activity (main) Pause, UserClosed = false **
    ** Activity (activity2) Create, isFirst = true **
    ** Activity (activity2) Resume **
    ** Activity (activity2) Pause, UserClosed = false **
    ' Manually kill the process, then open app again
    ** Activity (activity2) Create, isFirst = true **
    ** Activity (activity2) Resume **
    ** Activity (activity2) Pause, UserClosed = false **

    I'm confused. So, is this normal??? I tested some apps on the market. If I kill those apps, they will open with the main activity.
     
  8. klaus

    klaus Expert Licensed User

    Do you have
    Activity.Finish
    in the Activity_Pause routine ?
    If no, as long as the application is not killed you'll see the last visible activity.
     
  9. ducphu

    ducphu Active Member Licensed User

    @klaus I dont use Activity.Finish and yes I know if the app is not killed, it will be opened with last activity. But,my problem is, even I purposely kill the app, it is still opened with the last activity, which I dont want.
    @Peter Simpson I dont want to make it complicate. Basically, what I want is, if my app is NOT killed, it is opened with last activity. If my app is killed, it should be opened with main activity. My problem here is, even my app is killed, it is still opened with last activity.

    Hope I explained my problem clearly.
     
  10. klaus

    klaus Expert Licensed User

    Without seeing your code it's difficult to help.
    How do you kill the the app ?
    The small attached example works as expected.
     

    Attached Files:

  11. ducphu

    ducphu Active Member Licensed User

    @klaus Weird, to me that example doesn't work as expected.
    I kill the app using an app from the market, i.e Watchdog
    If that example works for you then maybe Watchdog doesn't really kill the app :eek:
    Any suggestion how to or which app can be used to "really" kill the app.

    P/S I just tested using Watchdog to kill some commercial apps like LINE Tools, Unit Converter.
    What I observed is, for LINE Tools, after being killed by Watchdog, it open and show the main activity.
    For Unit Converter, after being killed by Watchdog, it open and show the last activity.
    uhmm so I think there should be some tricks behind to determine which activity will be showed....:confused:
     
    Last edited: Jan 29, 2015
  12. thedesolatesoul

    thedesolatesoul Expert Licensed User

    1. Dont use a process killer. Use 'Recents Menu' and then swipe to kill.
    2. How are you re-launching the app?
     
  13. parijs

    parijs Active Member Licensed User

    Maybe LINE Tools has only one activity
     
  14. ducphu

    ducphu Active Member Licensed User

    @thedesolatesoul thx you... if I use recents menu to kill, the app will load back main activity. Interesting, so those process killers don't really kill the process... I'm wondering what those apps do...
    @parijs oh yeah maybe...that app has many functions and I didn't think that they put them all in 1 activity....
     
  15. thedesolatesoul

    thedesolatesoul Expert Licensed User

    After killing them, were you loading them from the recents menu or from the home screen?
     
  16. ducphu

    ducphu Active Member Licensed User

    Home screen
     
  17. ducphu

    ducphu Active Member Licensed User

    May I ask the right way to check if an app is still alive or killed?
     
  18. susu

    susu Well-Known Member Licensed User

    Try in System settings menu / Apps / Running
     
  19. ducphu

    ducphu Active Member Licensed User

    Apps / Running doesn't seem to be reliable. I test with "Two Activities" example. When the app is not in the running list, both "running services" and "cached processes", the app seems still alive. It still loads the last opened activity.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice