Here is the sequences that triggers my "bug".
I launch my app. Then I receive a new snapchat/sms/anything new. I pull the notification bar from top of my phone and clic on that new snapchat which makes my phone launch the snapchat activity. If now I press the back key it goes back to my app BUT, OnWindowFocusChanged is not changed ! Why ? How do I handle this ?
Related
I need show PIN Code activity after that (we have App with many Activities):
User press hardware button "Home" and go back to App.
List item App Screen go to sleep mode then go back.
What ways do I need to use?
capture home key event(KeyEvent.KEYCODE_HOME) and sleep event(Intent.ACTION_SCREEN_OFF) ,use a variable to record it.
when go back to app activity judge the vaviable and show your PIN code activity.
I am calling one activity on click of status bar notification which is having a Complete button. on click of btn. i have folllowing code -
public void completeTask(){
taskDBAdapter.deleteReminder(rowId);
taskDBAdapter.close();
Intent intent = new Intent(this, TaskManagerActivity.class);
startActivity(intent);
finish();
}
whhen i click complete btn new activity (TaskManagerActivity) gets opened properly.But if i reopen my application it still tries to open this activity and not my default landing activity. Any help on this.??
EDIT -
I have tried repositioning my finish() statement . Still its not working.
EDIT 1.1 -
Ok I will provide some details here. Assume my app has two activities
Main Activity
Notification Activity
My app create some notification to display on Status bar. So as soon as i click on status bar Notification actvty will open. Now there is a button called Complete on click of which the code given will fire and main activity (in the code TaskManagerActivity.class) will open. But after I press back button in my app and again reopen it , it opens the notification activity when it should have fired the main activity (as it is launching activity).
Thanks,
Ray
That's the default way android functions. If you press the home button and then open your app again, it will restore the apps previous state (unless it has killed the apps processes and activities due to memory constraints). So you are not actually restarting your app but only restoring it.
If you wanna quit the app, then press the back button. Now when you re-open the app, the original activity will be launched.
Do not modify this behavior. It is the default system behavior and users expect it to work this way. Your app is fine :-)
- First of all the behavior which you are experiencing is the way Android is made to function, moreover when a user gets a call while this app is open, after finishing the app he will definitely want to get back to the state where he left the application.
Still if you want it that way, here it is.....
- Make sure your application has only single instance of it running, by using android:launchMode="singleTask", or android:launchMode="singleInstance"
- Then finish() your Activity at onPause().
#Override
void onPause()
{
super.onPause();
finish();
}
All,
i tried different things and finally thought i post this question.
My application has 2 modes. one is with out registration and other, with registration.
in without registration mode, application has to behave just like normal android application. means, if user goes like A-> B-> C and at C, he clicks home button and relaunches the app, the app should come back to C, which is normal behavior.
in second case, if user is registred user and he is at A->B->C and relauches the app using home button, then it should not take him to C but it should take him to "log in screen"?
how to achieve this as we will not know that activity is being started from another activity/home screen?
i tried "single top" with onNewIntent() but looks like onnewintent() is not getting called when launched from homescreen. all ideas are welcome.
onNewIntent is not recalled because when you press home button application just goes to background try onResume
I want the user to enter a password everytime he tries to enter the application. That is, the user must enter the password everytime the app comes to foreground from background, be it by pressing the launcher icon or long-pressing the home key
I sort-of achieved the first part because the launcher intent is fired and i get a callback in onRestart of that activity.
But by long-pressing home key and launching the does not provide callback to onRestart.
Also what if the user launches the app by pressing the notification from, the notification bar. How do I distinguish whether the app was originally in background or fore-ground before the user clicked the notification
In your onResume call, set a loginCounter += 1, in your onPause -= 1.
if loginCounter == 0 => show Login Dialog.
In the Notification Bar you set an Intent to call the Activity, correct? Simply add a parameter "isCalledByNotificationBar" as boolean in there.
If onResume doesn't work, how about onWindowFocusChanged(boolean)?
Perhaps what you should do is on re-entry into the application see if it's been less than 30 (?) seconds since a timestamp that you update when any activity of your application was last paused. If it's been less, don't ask for a password. Thinking being that this short time window might smooth over some transitions you don't want to log out on.
In one of my services I fire an event that puts a notification in the status bar which includes a pending intent to start an activity when the user clicks the notification.
The activity I'm starting is actually a "popup" that has the theme of a dialog popup (android:theme="#android:style/Theme.Dialog") defined in the manifest. The code for the pending intent is below:
Intent intent = new Intent(this, PopupWindow.class);
PendingIntent launchIntent = PendingIntent.getActivity(context, 0 , intent, 0);
notificationManager.notify(notificationRef, notification);
Everything works fine in android 2.2, but when testing in android 2.1, the newly started popup window doesn't take focus on the screen.
I know the activity is starting, because if I hold the home button down to bring up recently started apps, the "popup" will magically appear and takes focus.
Is there something I'm missing here? Why does my code work in android 2.2 and not 2.1?
After a day of debugging, I found that the new activity launched from the pending intent (Activity B in the stack) would get lost somewhere in the ActivityManager behind either the already opened activity (Activity A) or possibly the window of recently opened apps (long press on home key).
This happened ONLY if navigated away from Activity A with the use of a long-press on the home key ONLY in versions of android < 2.1. Every other instance of navigating away from Activity A (home key short-press, back-key press) would allow the pending intent on Activity B to open and take focus above everything on the screen. In android 2.2 and above, the code works absolutely fine with no issues. Very weird. To make things even weirder, if I put a Toast message to be displayed within the onRestart method of Activity A, the issue completely disappeared. There is nothing weird going on inside the onPause method of Activity A either....I still don't know.
I tried almost all flags on the pending intent for Activity B, but none of them would allow the popup to get to the top of the activity stack....I think Nanne and willytate put me on the right track...
I abandoned the method of setting the pending intent inside of a service, I think it was breaking the affinity between Activity A and Activity B. When I set the pending intent for Activity B inside of Activity A, as apposed to inside the service running in the background, Activity B (in the form of a popup via android:theme="#android:style/Theme.Dialog" in the manifest) would always appear at the top of the stack.
Once again, this "loss of focus" on an activity has only ever happened to me in this process:
Android 2.1
Launch Activity A
Use service to set status bar notification with a pending intent to start Activity B
Navigate away from Activity with long press on home key to any other application.
Service fires notification in status bar with intent to start Activity B.
Click notification to open Activity B.
Activity B, created as a dialog, is no where to be found and Activity A comes to the stop of the stack, but remains paused. No response to user touch at all on Activity A and the timer being displayed isn't moving. The Activity is stuck in onPause maybe?
The only way to get Activity B to appear is to, once again, long press the home key. When this is done, I see the following on the screen, in descending order with the first as the one at the top of the stack ready for user input :
List of recently used apps.
Activity B.
Acitivyt A.
Pressing the back button to dismiss the list of recently used apps will allow Activity B to take user input, and from there everything runs normally.
If this was not a complete waste of time, I did get a much better understanding on how Android handles the application stack.
Can anyone else (if they really wanted to) re-create this issue?