Android Question Problem: White screen after StartActivity

Discussion in 'Android Questions' started by RodrigoVitachi, Sep 4, 2015.

  1. RodrigoVitachi

    RodrigoVitachi Member Licensed User


    I have a problem that is not so usual.
    There are a few activities in my app, and a Starter service. From time to time, my service starts an Activity, and that is fine, working 100%.

    The problem is when the user opens the "recent apps" Android list and closes my app by sliding it off the list.

    The result is: My app is closed, but my service is still running. Then when the Service tries to open the activity, it comes all blank, with 0 responses, doesn't trigger "Activity_Create" nor "Activity_Resume".

    Is there any solution for that? Open an activity of my app after it is closed?
    IF the answer is NO, then is it possible to detect that the user is closing the app from the Android apps list? Then i could also stop the service.
    Or, how can i test if my app is still alive before trying to start the activity again from the service?
    The last chance would be to hide the app on the active apps list, then the user could not close it. Is it possible? How?

    Waiting for some help.
    Last edited: Sep 5, 2015
  2. corwin42

    corwin42 Expert Licensed User

    Never seen such a problem.

    Without some code seeing what you are exactly doing, no one can guess what happens.

    Best thing would be if you can create an example project which shows this error.

    Btw: You posted your question friday evening and now it's weekend. Do you really expect that Erel ist working day and night just to answer your questions?
    DonManfred and Mahares like this.
  3. RodrigoVitachi

    RodrigoVitachi Member Licensed User

    Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim PE As PhoneEvents
    End Sub

    Sub Service_Create
    End Sub

    Sub PE_UserPresent (Intent As Intent)
    End Sub

    I don't believe this is a code issue, simply because it works. The problem is when the user closes the app by dragging it off the active apps list, and this service is still active, then tries to start the activity when the app is already dead. Then i have the blank screen.
  4. RodrigoVitachi

    RodrigoVitachi Member Licensed User

    I am not expecting Erel working 24 hours, i was just expecting an active forum. And if aswering here is not to help people, if it is just WORK, then just charge the users and clients like me, i will pay for the help and everybody will be happy. Plus, considering your answer, i am pretty sure that you didn't even read my post, giving a vague answer, and this is not the kind of help that i or anyone else needs. Thank you very much for your expensive time.
  5. RandomCoder

    RandomCoder Well-Known Member Licensed User

    I'm sorry but I agree with @corwin42 you have not provided enough information to be able to offer advice that would be of any help. The problem is most likely in the SignUp Activity Create routine as this is what you are calling with your service. Or maybe the PE_UserPresent routine isn't being triggered under the special circumstances you mention. Maybe try placing a log statement in there to make sure it's being called?
  6. RodrigoVitachi

    RodrigoVitachi Member Licensed User

    \o/ FTW.
    For anyone with the same problem, which means, trying to re-open an activity from a service after your app is killed, here is a workaround.
    Add this line to the manifest:
    SetActivityAttribute(Main, "android:excludeFromRecents", "true") , where Main is the name of the activity that you want to hide.

    This way the user won't kill your app accidentally because it won't show up on the "recent apps" list. This is not the perfect solution, because there are many ways to kill the app then the blank screen will come back, but, you avoid the easiest way to kill it.
    Last edited: Sep 5, 2015
  7. RodrigoVitachi

    RodrigoVitachi Member Licensed User

    Now i am pretty sure that i could not explain the problem clearly. Like i said, the code works, and just stops working after the user kills the app, which is ok, but when you try to re-open an activity from a service, after your app is dead, then you have a blank activity, with no logs, no responses, no "create" or "resume" triggers, just like i said on the first post. I already solved the problem with a simple workaround, which is not perfect, but will work for a while. Thanks.
    Last edited: Sep 5, 2015
  8. RandomCoder

    RandomCoder Well-Known Member Licensed User

    This is the bit I have trouble understanding. If you are calling an Activity it will always call Activity_Create and/or Activity_Resume.
  9. RodrigoVitachi

    RodrigoVitachi Member Licensed User

    Yes, and that is the problem. It works 100%, but only if the user doesn't close the app. If the app is killed and the service tries to open the activity, then you have a blank activity with 0 response, no triggers, nothing.

    Steps to reproduce:

    Create a Starter service that restarts itself every 1 minute or 10 seconds ( the time is not important here ).
    Every time the user is present ( unlocks the phone screen ), you start an activity.

    It will work, every single time.

    Now, close the app using the "recent apps" list. Your service will still be alive and will restart.
    Now with the app closed, the serviece will try to start the activity again, if you unlock your celphone ( UserPresent trigger )
    Now you will have a blank activity.

    I tried many workarounds, no success. I tested the app in different devices, same problem. It seems like basically there is no more activity to open after the user closes your app, that's why we have a blank activity.

    A simple way to prevent this behavior is to hide my app on the recent apps list. This way the user should use an option inside the app to close it, then i can stop the service as well. Not perfect, maybe not even a good solution, but i have no choice.

    Thanks for your time and reply.
    Last edited: Sep 5, 2015
  10. corwin42

    corwin42 Expert Licensed User

    I was able to reproduce your problem now.

    It happens only if you start the activity from the starter service. If you use another service it works without problem.

    I think we have to wait for Erel to comment on this. Maybe this is a bug in the starter service.

    Because of these words I thought some time if I should answer again to your question. You should think about it...
    Last edited: Sep 5, 2015
    RandomCoder and RodrigoVitachi like this.
  11. RodrigoVitachi

    RodrigoVitachi Member Licensed User

    Thinking a little bit more about this activity behavior, i am not sure if it is a bug, because the app actually doesn't exists anymore, it has been closed. I don't know how it works inside.
    You are right, the best thing to do is to wait for Erel, but i'll keep my workaround for now, preventing the user to close the app with the recent apps list. Not the best solution, but, it's what i have. Thanks for your reply;
  12. corwin42

    corwin42 Expert Licensed User

    I think a better workaround would be not to use the starter service to call the activity but use a second "normal" service (which can be started initially from the starter service of course).
  13. Erel

    Erel Administrator Staff Member Licensed User

    You shouldn't start an activity from the starter service. When the starter service starts there is always an activity or service that should start right after. The one that the OS intended to start. You should let it start and only then switch to a different activity if you like.
    lemonisdead and corwin42 like this.
  14. PhilipBrown

    PhilipBrown Active Member Licensed User

    Has this problem been resolved? One possible solution might be to use a notification, which will start an activity if it is not already running.
  15. gmachacek

    gmachacek Member Licensed User

    Hallo i still facing this problem.
    I have a widget with a labelview as button lets say. when i click first time and from service start the activity i just see empty screen.
    Then when i close the empty activity just with buttom back so that it runs in the background and open it again then all elements are shown probably.
    lg georg
  16. Erel

    Erel Administrator Staff Member Licensed User

    Please start a new thread.
  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