Android Question Advice on Services

Derek Jee

Active Member
Licensed User
Longtime User
Hi there

I have an app which need to 'log out' the user after 2 hours whether the app is visible or the device is sleeping etc so not necessarily in the foreground. I am currently using a service to start in 2 hours which forces the login screen to the forefront.. The service start gets updated each time an activity is accessed or left.

My questions are
1 - How can I combat the device destroying this service in low memory situations? I have read the service module info but just wanted advice on my scenario..
2 - Can I force the login screen to be the forefront of the app but not to be in the foreground when the service runs.. I don't want the user to get the login screen if they are browsing the internet or on the phone for example but just to show when the user reactivates the app.

Thank you for your advice in advance..

Derek.
 

Jmu5667

Well-Known Member
Licensed User
Longtime User
Hi there

I have an app which need to 'log out' the user after 2 hours whether the app is visible or the device is sleeping etc so not necessarily in the foreground. I am currently using a service to start in 2 hours which forces the login screen to the forefront.. The service start gets updated each time an activity is accessed or left.

My questions are
1 - How can I combat the device destroying this service in low memory situations? I have read the service module info but just wanted advice on my scenario..
2 - Can I force the login screen to be the forefront of the app but not to be in the foreground when the service runs.. I don't want the user to get the login screen if they are browsing the internet or on the phone for example but just to show when the user reactivates the app.

Thank you for your advice in advance..

Derek.

Hi Derek

I would suggest the following:

1. Call your service's using a scheduled callback, startserviceat()
2. If the service needs to present the user with a login screen, set a global value main, say mainLayout = "login", and the issue StartActivity(Main).

Hope this helps you

Regards

John.
 
Upvote 0

Derek Jee

Active Member
Licensed User
Longtime User
Hi Derek

I would suggest the following:

1. Call your service's using a scheduled callback, startserviceat()
2. If the service needs to present the user with a login screen, set a global value main, say mainLayout = "login", and the issue StartActivity(Main).

Hope this helps you

Regards

John.

Hello John

Thank you for responding.. Does the StartServiceAt deal with the device destroying the service in low memory situations? I will be implementing a global variable for the activity I have to revive after sleep so that suggestion fits very well but does it not activate the app when the service starts the activity? I would like it to activate the activity but not activate the app unless it was currently being used by the user..

Kindest regards,

Derek.
 
Upvote 0

Jmu5667

Well-Known Member
Licensed User
Longtime User
Hello John

Thank you for responding.. Does the StartServiceAt deal with the device destroying the service in low memory situations? I will be implementing a global variable for the activity I have to revive after sleep so that suggestion fits very well but does it not activate the app when the service starts the activity? I would like it to activate the activity but not activate the app unless it was currently being used by the user..

Kindest regards,

Derek.

The startServiceAt should be ok for you. In any OS if there is not enough memory then you cannot do much about, but android is quite good at this. I might just add the data in the main activity may be unavailable when your service starts, I would suggest your create a type structure to hold all your data or you can write it to a keystore db file.

I think you might be confused with the app/activity bit. You should think of an activity as a user interface (Windows Forms etc.). Do not put any processing code in an activity, user mod's for that. So, when your service is started again the activity will not be started unless you activate it. A service is in independent process and can run when every you like.

I have one particular app then has a few services that run in the background independent of the UI (Activity). These services handle GPS/Bluetooth/WiFi/IBeacons and socket connections to back end servers for data delivery.

Hope this helps you.

Have fun

Regards

John.
 
Upvote 0

Derek Jee

Active Member
Licensed User
Longtime User
Hi John

I am in the lucky position to have had an Irish mother and English father so I hedge my bets.. Haven't seen much though as I've had an unusual bout of 'other things to do' but I am sure I'll catch the important ones.. You liking it too?

Thank you for the advice. I only ask about the service 'starting' an activity as it seems in testing that when I leave it to start the activity it wakes the app and shows the login activity but I do not want that to happen.. Should I use that variable to catch what I should be opening when activities resume in that case?

Thank you again John..

Derek.
 
Upvote 0

Jmu5667

Well-Known Member
Licensed User
Longtime User
Hi John

I am in the lucky position to have had an Irish mother and English father so I hedge my bets.. Haven't seen much though as I've had an unusual bout of 'other things to do' but I am sure I'll catch the important ones.. You liking it too?

Thank you for the advice. I only ask about the service 'starting' an activity as it seems in testing that when I leave it to start the activity it wakes the app and shows the login activity but I do not want that to happen.. Should I use that variable to catch what I should be opening when activities resume in that case?

Thank you again John..

Derek.

Yes, on the activity resume check which layout to load. BTW, this year RWC is fantastic, and I'm not s sporty person :)
 
Upvote 0

Derek Jee

Active Member
Licensed User
Longtime User
Thank you..

and me neither, but a good Rugby World Cup is never to be missed..

Thanks for your help today John, much appreciated..

Derek.
 
Upvote 0
Top