Flutter - Do not restart application when restoring - android

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.

Related

stopping the user from forcing stop my app

About Android (6.0 to the last version)
I'm developing an app and we want that the user, once he accepts all the terms, don't be able to kill the process or force stop the app. Honestly, I'm completely lost right now, because on the last versions of android, and specially some brands like Xiaomi, we are having a lot of trouble with it, and we don't know how to act right now.
In the case that it could not be possible, could at least get an alert whenever the user is killing the app?
Thanks!!
It is not possible to prevent the user from killing an app. Android is a unique system where the app has no direct control over its lifecycle but the system has. The system can (and will, when required) kill the app or any of its processes at its own will. To make your app aware of these changes, the android framework provides for various callbacks such as onPause, onStop and onDestroy which are called in succession when the user kills the app.
Side Note : There is no guarantee that onDestroy() will be completely executed when the app is killed. Do not place essential code there.
Of course, you can block or try to prevent the user from closing your app by overriding the back, home and recent buttons but it is highly recommended not to do so. Even if you do so successfully, the user has other means to close your app such as rebooting their phone.
So what to do?
You are looking for a kiosk mode app. Kiosk mode is used for single purpose phones such as at a restaurant or for a cab driver. Kiosk mode apps lock down the user to only a specific app (or a specific set of apps).
For normal apps, it is not possible to prevent the user from force closing your app. You can only get alerts by checking for lifecycle changes as described above. Moreover, it is not at all recommended to change the natural behavior of the hardware buttons on android. The user can still find a way to close your app. If your app is doing something really essential which should proceed in the background, consider using a service for that instead. Also, the user can uninstall your app at anytime if they find your app being too intrusive and you won't be able to do anything in that scenario.
Tl;dr: Use kiosk mode to prevent the user from exiting the app. This will only allow the user to access your app(s) in their device.
Usually you cannot! Even if you try to disable some buttons, user can always stop app or restart device. In addition at times, the OS will stop the App. Your responsibility as a programmer is to program around this, and give the user the feel that it never stopped. If you are doing background monitoring, you will need to use service. Users will still be able to stop service. Having said that, you can set your app as a Device Administration app, see here, which may disallow stopping, but unless you are distributing internally to a company, noone will install.

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 App quits automatically if its idle for some hours

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

What happens when android app is "killed"

I have an app which has real time push notifications enabled. So my query is whenever any user tries to kill my app using "Advance Task Killer", my app goes into undefined state.
Undefined State: What i mean is my app doesn't gets completely terminated. The screen has data in a inconsistent state.
So is there way where i can take a user to login screen back whenever an app is killed. So that user wont see any undefined state.
Also want to know what happens to my app states after it gets killed so that i can fix the issue.
Help Appreciated.
It depends on the version of the platform. Prior to 2.2, third party applications like ATK could use an API that did the same thing as the "Force Stop" button in manage apps -- this kills all app processes, removes all tasks/activities, unregisters all alarms, removes all notifications, stops all services, etc. Basically make the application not running the same as if it was first installed, except its persistent data is still intact.
Needless to say, this tends to cause misbehavior of applications, so as of 2.2 other applications like ATK can no longer do this to your app. The API they were using is now only able to do the same thing that the out of memory killer does -- kill the application processes but only if they are in the background in a killable state. It can do no more than the normal out of memory killer, so as of 2.2 if your application is misbehaving due to an app like ATK being used on it then this is exposing an actual bug in the app that users will encounter through the normal use of their device.

How to force all activities in an application to always be destroyed (for testing purposes)?

I am basically looking for the same functionality found in the DevTools (Development.apk) app that comes with the emulator. I am wanting to perform similar testing on an actual device but the DevTools app does not work properly on the device I have so I cannot use it.
I am looking to test in a similar way.
What this does is causes each Activity to be destroyed whenever it leaves the screen, holding onto its instance state just as if the system needed resources and had killed it. (So I can't just call finish)
Is there a way to do this?
Thanks
You can kill your app's process at any time using the DDMS stop button. highlight your application in the list and click the stop sign button. your application will be destroyed like it was killed by the system.
See the stop button in the left pane(Devices) above each device listing:

Categories

Resources