Android, what really happens after force closing an application? - android

I have an stock market application. When user login to application, server sends me a session key. This session is valid until user logout the application or don't do anything for several minutes.
My first problem (that is solved already) was when after login to application, user click home button and after that click on icon of application. Now, after login, a message (sent by server) showed "your user id is in use". I have solved this issue by saving session id in shared preferences.
Now, the client reported that we have same issue based of this story.
User login to application
After that user clicks home button
User goes to settings/applications/manage applications
Selects application and then in "Application Info" page, clicks on Force Stop button
User comes back to application list again and selects the application
After login, "Session Expired" message will show and application directed to login page again
Now, when user try to login, the above message ("your user id is in use") will show while session id is not expired.
I want to know, what "Force Close" button really do? Does it clean all instances of activities? When I click and hold Home button, I can see that I still have an instance of the application in memory. Therefore, what is the role of "Force Close" button?
Now, if user enter his/her password "your user id is in use" will show again.

When any application is ForceClosed.
The Application is Closed and Android Clears all the memory occupied by the Application.
That's why when you force close the application your static data member's are destroyed and removed from the memory.
Here,You can use SQLite DataBase for better performance.
ForceClose Means : Close the Running Application and Free the Memory.

Your question has been answered, but I'd like to add one point. You mention that
when i click and hold Home button i can see that there is still i have
instance of application in memory
Please note that what you see when you long press the Home button is the list of recent apps and not the list of apps currently in memory. Hence, even if an app has been force-closed, you will still see it in this list since it was recently used.

Actully when you just back & exit to the application....
see at phone setting, application.
your application was not close at our phone.
that is still alive & it runs at backend.
after force close application it close from backend also.

Related

How to detect when user returns to app specifically via "Recent apps"?

I have my own pin code activity in my app which popup every time user returns to the app (on first start or when the app was in background). I found it curious that some bank apps can somehow detect when user just jumped to another app via "Recent app" and then return to the bank app (in this case PIN activity will not show up in these apps). How did they do it that when returned from Recent Apps, pin code activity will not be triggered?
I tried androidX´s LifecycleObserve and ComponentCallbacks2.
Currently I´m using registerActivityLifecycleCallbacks to generally detect when user leaves the app, but I have not idea, how to programmatically differentiate these two cases? Any ideas?
I have my own pin code activity in my app which popup every time user returns to the app (on first start or when the app was in background). I found it curious that some bank apps can somehow detect when user just jumped to another app via "Recent app" and then return to the bank app (in this case PIN activity will not show up in these apps).
What makes you so sure they're detecting that you came back from "recent apps"? If you go to a bank app, press back to close the app, then re-launch it from the list of apps, you may not be prompted for a pin or password.
If you leave the app for long enough and come back to it from "recent apps", you may be prompted for a pin or password.
More than likely these apps are employing some kind of time-based heuristic, although this will of course vary by app.
How did they do it that when returned from Recent Apps, pin code activity will not be triggered?
I don't know how "they did it", but as for the the question of "how can I know my activity was launched from recents"? Try looking for FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY in your intent.
Hope that helps!

How can I make my android app such that whenever it is opened through recent tabs it goes back to main_activity?

I want to make an android app where the user first has to enter the password and then is taken to the subsequent activities.
But the user is able to access the last opened activity through recent apps without entering password.
So I want that every time the app is opened through recent tabs the user gets guided back to the main_activity where he first has to enter the password.
A good option would be to logout the user whenever your other activities go onPause(), and then when the activities are created, send them to the password activity if they are logged out.

Alert mechanism needed when user clicks the Force stop in android app

I am new to android development and so please apologize if my question is very simple.
I am trying to build an android app which is a location based app, through which users (say Person A) can track another users (say Person B) location continuously.
In app settings, we have an option called 'Force stop'. So from the above case, anytime Person B can kill my running app using this 'Force stop', so that his location will not be properly monitored by Person A.
I need to avoid this. I have to continuously monitor Person B's location and make him to avoid killing my app using 'Force Stop'. how can I achieve this?
Is there any way in android to call a particular method (so that I can have some alert code to person A) when Person B clicks the 'Force Stop' button.
Or is there any way through which, even if Person B stops my app, I can alert the user and restart my app again!
Suggestions please.
Thank You.
There's no way that user B's app can notify user A that user B clicked "Force Stop", because "Force Stop" brings everything to a halt immediately.
However, user A can infer it if user A's app is expecting regular updates from user B. If user A's app pings user B every minute, and after 1 minute user B's app does not respond, then user A's app can assume that user B's app is "dead". This is probably a better way to do it, anyway. Other things besides "Force Stop" can cause user B's app to be unavailable: user B turns off the device, user B can no longer communicate with user A, Android considers user B's app to be low priority and kills it, user B app crashes because of a bug, etc.
You need to use DeviceAdmin api for that. user can't uninstall your application if it enabled as an admin.

Using home button on android phone

In iphone when we exit app and start app again by clicking launcher icon the app start from screen which was open last time before exiting app.
We can achieve same in android when we exit app using center or home button on android phone. In android app if app is exited by pressing home button and started again by clicking on launcher icon the app start from activity which was open last time before exiting app.
Is that functionality similar to iphone in terms of keeping app in memory longer? Will that work in android all time because I think android system will remove app from memory after sometime or will it remain in memory longer? Can I depend on this functionality in android and expect it to work all time.
I have a project in android which client has asked me to have iphone like functionality if we exit app and start app again it should open from screen which was opened last time before exiting. Now this is possible in android only if we use centre button. And also if user has exited using centre button and started it again, app should check for user current location and do some other operations. If app is launched and user navigate to any activity is there any way to check if app was exited using back button or centre button so that I can run code if app is exited using center button.
Thanks
We can achieve same in android when we exit app using center or home button on android phone.
The HOME button does not "exit app".
The HOME button brings the home screen to the foreground, just as the CAMERA button (where available) brings the camera application to the foreground, the CALL button (where available) brings the dialer to the foreground, tapping on a Notification may bring something else to the foreground (e.g., SMS client) based on the Notification, etc.
In android app if app is exited by pressing home button and started again by clicking on launcher icon the app start from activity which was open last time before exiting app.
No. If you tap on a launcher icon, and the app's process is still in memory, the existing app instance will be brought to the foreground, returning you to whatever activity you had been on. If you tap on a launcher icon, and the app's process had been terminated to free up RAM for other apps, you launch a fresh copy of the app and bring up whatever the ACTION_MAIN/CATEGORY_LAUNCHER activity was that the user tapped upon.
Will that work in android all time because I think android system will remove app from memory after sometime or will it remain in memory longer?
The length of time that a non-foreground app's process will be in memory is indeterminate and will be based on what is going on with the device, plus the device capabilities (e.g., how much RAM). I suggest you read more about the process lifecycle.
Now this is possible in android only if we use centre button.
It is not possible "if we use centre button" (what Android developers refer to as the HOME button). It may happen automatically, but if the app's process has been terminated, it will not happen automatically.
If app is launched and user navigate to any activity is there any way to check if app was exited using back button or centre button so that I can run code if app is exited using center button.
You should not care whether the "app was exited using back button or centre button".
You should care whether you have your data and how old that data is, refreshing it if it is stale.
Whether the user left your app via HOME, BACK, CAMERA, CALL, a Notification, the recent tasks list, an incoming phone call, by smashing their phone to bits with a rock and replacing it with an exact duplicate, or by any other means, should not matter to you.
To draw an analogy, think of a Web app. In a Web app, you care about whether you have a session cookie and whether that session is stale (e.g., to force a fresh login). Whether the page request came because the user clicked a link within the app, or clicked on a link from a third party site pointing to your app, or refreshed their page, or used a bookmark to get at another page in your app, or double-clicked on a desktop icon that brings up your app, or right-clicked on a link and opened a fresh tab, or anything else, should not matter to you.
Review the Android Activity Lifecycle at http://developer.android.com/reference/android/app/Activity.html. If you do nothing, you have no guarantee of your app starting at the same point it left off, however you have control here. You can, for example, overload the onPause() method to save your state to a file, and onResume() to restore it.

I am facing unexpected issue in android app

I have two activities: Login and List.
When i log-in i display the list. When user is in the list activity and press the home button. After that clicks on the app icon it brings to login page for some times only. While it should display the list.
How to resolve this?
Your app is pushed out of memory sometimes in order to free memory for other apps. When it happens, app is re-launched when user enters it and first Activity is opened. The only(or not the only) way for you to maintain your app state is to store it somewhere. You could save whether user logged in or not in SharedPreferences and when Login Activity is created you could check this.
Sometimes your app will be killed depending on how much memory other applications need. Your application must save and restore its state in order to behave as if it hadn't been killed.
If you read the section on the Activity Lifecycle in the developer docs, you should understand what you need to do.

Categories

Resources