Android app (not activity) visibility change event - android

I have developed one small Android app for testing purpose. Now I need to know that how many users are online/active on my app. means any user minimize my app and go to android home, then I want notification/event and when he/she come again on my app, then also it should notify/event. Is it possible?

Unfortunately, there is no event that will tell you what you need.
But there are some workarounds.
Maybe try with this one: http://vardhan-justlikethat.blogspot.in/2013/05/android-solution-to-detect-when-android.html
or this one http://www.vardhan-justlikethat.blogspot.com/2014/02/android-solution-to-detect-when-android.html

take a look at the livecircle http://developer.android.com/training/basics/activity-lifecycle/index.html
When the system calls onPause() for your activity, it technically means your activity is still partially visible, but most often is an indication that the user is leaving the activity and it will soon enter the Stopped state
When the user resumes your activity from the Paused state, the system calls the onResume() method.

Related

Activity Lifecycle. When application already opened (Collapsed) is closing and starting again on icon click?

Can you please explain to me why my activity which is currently (onStop) is go to OnDestroy event and restarting again after clicking on the app icon in the interface.
Because of that i have problem with user data saving. I'm using event OnDestroy to ask user if he want to save the data. Because of my misunderstanding when i collapse the app and click to it again i am waiting to my activity to have all the data in it but instead i see saving dialog from the previous activity whiсh goes to onDestroy event.
Other apps don't act like this.
What should i check?
Your description is not very clear, so my answer may not help you.
Research the app life cycle here: https://developer.android.com/guide/components/activities/activity-lifecycle.html
Your app will enter onStop is before onDestroy. This can happen if user activates another app. (So the user may no longer see any prompts that you display e.g. To ask to save or not.) Android may choose to destroy your app based on its rules after that point, even if the user clicks on the app icon to start it again.
Perhaps you can test what happens if the user switches back to the app (not clicking the icon), but use the "Recent apps" button and select it.

What is the difference between launch app from "recent apps" and tapping app icon

I'm working on large project, so there is some logic for saving application state, and then opening correct activity(fragment) when it comes from background.
But anyway, I've found that if user navigates through my app and then minimize it - android opens it from background in different ways in following cases:
User taps on app icon (behavior: user see home activity, doesn't matter where he was, when application was minimized)
User select app from android "recent apps" (behavior: user see exactly what he saw, when the application was minimized)
So, what is the difference between launching application from background by this two ways? I always thought, that it is the same mechanism, but, obviously, I was wrong.
Thanks for any answers
You should pay atention on the folowing docs Activity and Tasks. In short words: if user start app from recents you will receive onRestart before onStart (without onCreate it means that your app was just "suspended"). You able to save screen state using onSaveInstanceState(). But in general starting from icon and from recents - different application behaviors and you should provide proper code for this ways.
UPD
As described below root cause of unexpected behaviour was additional lunchmode attribute.
From what I experience as an Android user, both are same.
The difference we usually see is how we close the app
Press back button until app close / finish()
On this state no matter how we open the apps it will go to the main screen
Press Home button
On this state depend on the app. If the app does not handle any Activity the app will same with the first state. But if the app handle something like when onPause() the Activity then finish() the apps, then whatever you open with app icon or recent apps will provide the same result.
Correct me if I am wrong

Adobe Flash Builder Flex Mobile Android: Avoid that user can close the app

I am developing an app for android. It is not always clear to me when the app will be terminated by the OS. Sometimes it happens when you press the back button and sometimes when you press the home button. What is the logic behind this?
My app must be keep activated during a long period (when you run it the app must stay resident). Also another question is if it is possible to popup when an event comes in and activate the screen and bring it to the front.
Does somebody made this already? Or is there more information about this (how to do it). Search the internet but doesn't find some useful things.
Pressing the Back button on the main activity will finish and exit the app.
Pressing the Home button will pause and leave the app in the background, it will return to the previous state when it's restored.
Override the onBackPressed() method on the main activity if you don't want it to quit when the back button is pressed.
If you want an event to occur when the screen is shown, override the onResume() method and do the checks and event required in there.
Being that your answer is with Flex the issue is that you need to listen to the stage's keyDown event.
stage.addEventListener(KeyboardEvent.Key_DOWN, yourHandler);
Then you need to response to the back button and inhibit this - if your intent is to stop the back button.
private function _onStage_keyDownHandler(event:KeyboardEvent)
{
if(event.keyCode == Keyboard.BACK)
{
event.stopImmediatePropogation();
event.preventDefault();
//your code here
}
}
And one more moment - android can close your app when it thinks that it need more memory for more recent apps.
And you may need to use native extensions or even develop your app in java if you want to implement reliable resident behavior.
Update: java service+ air ui example:
http://www.jamesward.com/2011/05/11/extending-air-for-android/
end of update
And you must know that air apps eat at least 30mb of memory(if they are empty and do nothing), normally they will start from 50-70mb. I guess that no user will wish to allow another 70mb of his memory-hungry device to be eaten by something not critical.
And for automatic maximizing of your window you may need root access.

It is possible to make a HoneyComb activity unclosable?

I'm developing a presentation style application for HoneyComb Tablets. At one stage the tablet may be passed around a room for people to interact with. If possible I would like to prevent malicious users from navigating away from the current activity.
So far I have overwritten the onBackPressed() to prevent finishing the activity but users can still press the other buttons on the status bar and also leave the app via notifications that pop up.
Any suggestions or possible solutions?
Thanks
1. Make your activity full screen.
2 Use an alarmManager to trigger your activity from a service on a regular interval say 2or3 second (only if your activity is not foreground). For this use a boolean variable and store it using sharedPreference. this value will be true in onReume and false in onPause or in onStop or in onDestroy. And then only start your activity from your service if the boolean variable is false. Now if your user will press the Home button then AlaramManager kick start your activiy again.
3 Make a special button for finishing your service and activity and for cancel the alarmManager.
As far as I know there is no way to capture the home button press, so this is not possible. Not to mention, it would be a bad ui design decision by the dev team. The home button is there so every Android user has a standard way to exit apps. There would be some extremely malicious apps if there was a way to make the user unable to exit an app.
I'm developing a similar application that runs in a "kiosk" fashion for retail stores. When the application launches, it programmatically hides the system bar so you cannot exit. The system bar is restored when the tablet is rebooted. It requires root/su however.

How to close an application when the Home button is pressed

Hi I have application with more than 20 activities.I want to close my app when Home button is pressed.
There is no notion of "close my app" in Android. Android will get rid of your activities, followed by your process, after some period of inactivity by the user.
You could use the launchMode and clearTaskOnLaunch flags on your root activity from your AndroidManifest.xml:
android:launchMode="singleTask"
android:clearTaskOnLaunch="true"
When you again start your app, all activities will be killed.
You don't want to do System.exit() -- that's not how the Android Activity Lifecycle normally works (read this also).
What you should do is move the App to the background with moveTaskToBack(). Android will then keep your app running in the background, and kill it if it's unused and something needs its resources later.
If you want it to close all of the open Activities when your App is no longer visible, you can set noHist = "True" for all of the child activities (leave the main activity with noHist = "False", though). This will make it where instead of reopening your application on the last Activity they were on, it will open it on the "main" activity (i.e. it will be as if they just restarted the app).
Anyhow, read through the following answers for more information: Close application and launch home screen on Android
I have the same problem. Im writing a banking app and am required, by contract, to log off the user (or exit) when the app is put into background. There are obvious security concerns there.
There are a couple of ways Im looking to do this:
1. Intercept home button (and back button for the root activity) key press events to call logoff and/or finish()
2. In the onStop() method, for every activity, detect whether the activity is being stopped due to a new activity being show - if not, assume app is being put to background so logoff and/or finish()
The first may not work if a notification is brought to the front then the user clicks home (I havent investigated yet). Or maybe there are other ways for an app to be put into the background without pressing these buttons
The second way sounds messy & difficult to maintain
Id welcome any other ideas
Drapes
I know android has been designed this way, but it seems naive to think that apps wouldnt want an applicationOnStop event
Hi guys what I understood is that u need to know when app goes in background and how to detect it and if I am wrong plz correct me----
The user can go in background if ur app does not provide any way by pressing Back key or Home Key.
You need to use methods "dispatchKeyEvent(KeyEvent event)" to get home key event or back key event and after getting the event you can execute your task.
you can even restrict user from pressing any key but u can not control the home key.

Categories

Resources