Android App quits automatically if its idle for some hours - android

I created an new Android app and succeeded in its working. Its all functionality are working fine. While starting it will ask use name and password.
What my problem was "If my Application is idle for some 4 to 5 hours, then automatically it get quit , while restarting its again asking to login"
I need to know how to avoid automatic quit of my app.
I'm sorry if its simple or already asked quetions.

I need to know how to avoid automatic quit of my app.
No, you do not. Simply redirect the user to log in again, or, as #Rasel suggests, persistently cache credentials in a file or database or something.
Android applications do not and must not live forever. Phones have limited RAM. Android will terminate unused applications after a period of inactivity, to free up RAM for other applications. This is perfectly normal, just as it is perfectly normal for a user to close a Web browser after visiting a Web app.

Its completely natural for the android application.Android OS automatically kill the process when it needs to do.So if you want keep your application alive you have to think differently.To keep always running you can use service that will monitor your application states and handle the situation when it prompts for the login info again.
Another option you can write the login information in the shared preference and can clean when user intentionally leave the application.So when starting again if you find the information you can directly prompt to the user without entering the login information

Related

Flutter - Do not restart application when restoring

Friends,
does anyone know how to prevent the application from restarting when restoring it? For example, the application is minimized, then restored and it restarts, any way to avoid it?
This is platform dependent, per example in android it depends on the ram available, if the device needs to free resources it will kill your app , if you add some native code to handle this you could do some things to prevent android from doing this. However. It's NOT recommended to do this. If the user exits an app, it wants that, to close the app. If the user presses the home button, it wants to go to another app, and android will keep your app running for some time in case your user comes back to the app.
The best way to do this, is to handle the default flutter lifecycle to store important data in case the system kills the app.

Android App restarts when I open it on my phone

I'm currently using a Samsung Galaxy S4.
I'm developing an app and as long as I don't exit it, it works great. However, if I leave it, it sometimes restarts itself completely and brings up the Login Activity.
I could select it from the active apps list, and it won't happen. If I go and open it up through pressing its app icon, it will sometimes restart. It will definitely restart if I remove it from the active apps list. How do I have it always return to its previous state in the app? Facebook manages it even when the app is removed from the active apps list.
Is Android garbage collecting my app for memory optimization? How would I avoid this.
The onPause() and onResume() methods might be what you're looking for. Check the Facebook SDK for details on persistent authentication, even when the app is closed. Check this SO post out for more details How to keep android applications always be logged in state?
And no, I don't believe this is Android doing any garbage collection.
Add this to the activity tag of your manifest to tell Android that your app will handle any configuration changes itself: android:configChanges="orientation|keyboardHidden"
To prevent users logging in each visit you can use shared preferences to save login credentials

Android service, need a service that keeps running

I am a beginner in Android development. I want to build a service that once started, must keep running.
Step 1.) Once user will install the app give some input, service will start. (i'll use IntentService)
Step 2.) Now user moves to other app/close my app. I want to make sure Service should keep running and processing/saving info with current timestamps.
Questions:
1.) How I make sure that the service keeps running/saving data even if user returns after say, 1 month on my app.
2.) I read that every app is a new user and separate VM is provided by the Android, question is when an app is considered to be closed?
3.) If my app closes, related services will also close then?
1.) How I make sure that the service keeps running/saving data even if user returns after say, 1 month on my app.
Once user installs app, you can start STICKY service but make sure you inform the user as well as Android OS by making it run on foreground with on going notification. it will help your service to run for long time without being killed by Android OS.
1 month is long period, user may reboot the cell in between. and you will need to restart your service. so you should register for reboot complete event .
2.) I read that every app is a new user and separate VM is provided by the Android, question is when an app is considered to be closed?
There is no condition like considered to be closed.Actually, when user installs app, it is by default in stopped mode, it gets activated when user opens your app for first time. and application can go back to stopped mode again whenever user force stop your app.
3.) If my app closes, related services will also close then?
If you are considering that app is considered as closed when user don't use the app,your service won't close unless Android OS kills it in low memory situation.you may make it foreground as suggested earlier to convey Android OS that you are doing important things,nothing is wrong,so kill me only at last when you don't have any other options left

Check if app is running and kill

I was wondering if I can kill app from other app. I mean I want to create application which when I start this application I will check status other application and if app, which name is for example "Startex" is running then I kill "Startex" app and run my second application.
No you can not. Only Android can kill application if it needs memory. In order to do this you should know the PID of the application you want to kill and invoke a syscall at kernel level
If both apps are designed by you then you can have shared user id in both the Apps then you can kill another app here is the way.
This can't be, or at least should never be done. Android itself is supposed to control when an app is no longer required, usually based on needing to free up some memory for another app that may be opened. Google frown upon developers killing the app themselves without letting Android handle it, and likely would never receive any promo place on the play store from Google.

Twitter Reauthentication

I have developed one app in which there is option for sharing on twitter.Its working properly fine.Now one requirement came which says that if the app is force killed it should again ask for authentication with twitter so that we can give user id and password again.The main thing is if user want to login to twitter with his new credentials how he will do that.Any idea how to solve this issue.Right now if i am uninstalling the app or clearing the data it is doing authentication but it should do on force killing the app.
You can't detect your app being force killed: https://groups.google.com/forum/?fromgroups#!topic/android-developers/xfkfRc-j4cw
It might be possible to set a flag when your app starts, and clear the flag when your app stops in an orderly way. If the flag is set when your app is starting, then you know it was last stopped in a disorderly way, like being force killed. This method of detection will probably give you both false positives (if someone pulls the battery out of their phone, your flag will probably still be set) and false negatives (if your app considers itself to have been stopped in an orderly way, and is then force killed). This method will surely give you angst and tears unto the fifth generation. Here be dragons, and the dragons will eat you.
You should push back against the requirement.
For your problem, you can clear your tokens when the app starts again, in an onStart(); method for example. So next time the user will use the application after the forced kill, this last wouldn't get any access tokens to work properly and would be consequently "forced" to ask tokens again via a classic OAuth Authentication Flow.
Reauthentications are just like classic authentications. At the end, the Twitter API will give you back the missed (or deleted) access tokens.

Categories

Resources