I am working on a complex Android app and found a strange problem.
The problem occurs when I start an activity to show a dialog.
What have I tried
I tried to search for similar problems ("Android activity blocked by home activity" etc) but could not find any.
Due to the complex nature of my app, I still cannot find the minimum representation of the cause -- The Description section below cannot be used to reproduce the problem. It is just something that I think is closely related to the problem. The real cause could be interactions between different subsystems.
Description
The activity is launched by a service with intent flags = FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TOP, which ensures that it will be the topmost activity at the point when it's launched. In its onCreate method, the activity set its window flags to be FLAG_SHOW_WHEN_LOCKED | FLAG_FULLSCREEN | FLAG_TURN_SCREEN_ON | FLAG_DISMISS_KEYGUARD, which ensures that even if the screen is locked, the activity will still be displayed. The dialog is also built and shown in the activity's onCreate method.
The app is tested on Android phones with screen pattern locks using the following steps:
Start the app. Press home button to return to the home activity. Remove the app from the recent app list.
Turn off and lock the screen by pressing the power button.
Ask (through GCM, to be specific) the service to launch the activity once. Dialog is then successfully shown.
Don't click any button on the dialog. Lock the screen again.
Ask the service to launch the activity once more. This time the dialog is also shown but instantly disappears, leaving the screen pattern lock shown.
Unlock the pattern lock and something strange appears: The dialog is now shown behind the home activity. The dialog doesn't respond to touch event. It's just like a wallpaper.
Android Version seems to matter
The problem seems to be only affecting some of the versions. It occurred on a Galaxy Nexus (Android 4.4.2) but didn't occur on a Galaxy Tab 3 (Android 4.1).
Accidentally the problem was solved by removing the line
android:theme="#android:style/Theme.Dialog"
for the activity containing the dialog from AndroidManifest.xml.
I am not sure why it could be solved in this way though.
Related
I have got the multi-window feature to work however, this is applied to all activities across the application. I would like to know is there a way to specify which activity that can use multi-window? For example, I have an introduction slider in which I would like to disable the feature and re-enable in the main activity. Thanks.
By launching activity in new task stack, you can accomplish this. But from user experience point of view, this may not be a good solution.
When app is in split screen mode, launch the activity, which you don't want do display in multi-window mode, by firing intent. Make sure that the target activity config in manifest is not multi-window enabled.
To go back to multi-window mode from full screen, you need to launch main activity in a new stack with below intent flags.
FLAG_ACTIVITY_LAUNCH_ADJACENT and FLAG_ACTIVITY_NEW_TASK
My app is built with the support ActionBar to allow for a standard UI between Android 4.x and Android 2.3, and for the most part this works fine. However, the title is not displayed in the ActionBar when I first launch the app under Android 2.3.
If I rotate the device to landscape mode, then the title appears in the ActionBar. After rotating the device back to portrait mode, the title is still visible.
What could be causing this? When I launch a different Activity in the app, that Activity's label (as specified in AndroidManifest.xml) is correctly displayed in the ActionBar.
EDIT: I've tracked this down to a splash screen Activity that is launched from the main activity's onCreate method. I can probably work around this be rearchitecting the app to launch with the splash screen as its default launch activity and then launch the main activity, but are there any other workarounds?
Unfortunately, I don't think "remove the splash screen" will be acceptable.
As far as I can tell, this issue is a bug in Android 2.3. It seems like this problem was caused by my launch Activity starting another Activity (the splash screen) from its onCreate method. Moving the splash screen launch to onStart or onResume did not help to resolve this issue.
I was able to work around the issue by replacing the internals of my launch Activity with the splash screen and creating a new "real main Activity" that the splash screen Activity launches.
It was important to keep the same class as the launch Activity because the app has already been released, and changing the class of the launch Activity would break shortcuts for users who have already installed the app.
I have a strange problem. im developing an app which overlays the incoming call screen. I have achieved displaying the popup window and everything works fine also i can access the receive and disconnect call controls below the pop up window on my galaxy s2.
getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
i've set the flags on my window to achieve the desired effect. But the while running the same code on galaxy s3/note 2. whenever i touch the screen anywhere my activity disappears! i have written methods to perform different actions on if the call is picked up or dropped. But i can never call those methods as the activity destroys itself just upon touch at any point of the screen.
How can i change the screen of an activity when pressing any button on an android phone that takes one away from the running app.
I'm trying to get a blank screen to show up on the "recents" screen, instead of a snapshot of the app.
You can use this option and check if it helps you meet your need.
android:excludeFromRecents="true"
Add this to your activities in the application manifest if you do not want the app to be shown in the recent apps list. One drawback is that you would not be able to resume the app from the Recents list. Not sure if this is what you need.
The other way is to have a 'Blank Activity', which you start when your actual activity pauses. You can then finish the 'Blank Activity' on its Resume. This way, you will have your app shown on the Recents list, but with a blank screen.
You can call finish() for activity but that will kill activity. I think that will leave blank screen. Or destroy(). Try both respond with results.
you might want to change the onpause() or onclose() functions of your app. they are the last thing android execute before leaving,therefor you can change the aspect off your app just before you leave it
EDIT :
Maybe if you create PopupWindow and set it to full screen, and color black when exiting no preview would be shown, but app would still be running (idea of user DjDexter5GH) in the onpause() and onclose() functions. therefgor,when you leave,a black(or whatever you want) screen is pushed in front
you can then close it in the onrestart(is it called this?)
I've searched SO and found several answers to the question in general, and have tried them all and am not having success. I really don't have my head around how the back stack works, Intent flags or the finish method. Here's my setup:
On application start-up, there's a splash screen where a couple AsyncTasks run in the background and check a couple webservers for updated content. ProgressDialogs report status. When complete (via the last onPostExecute), I launch a new Activity ("Home"). This seems to reflect some of the other posts, but I think my kludge is due to Home being a TabActivity, with 4 tabs, that initially calls setCurrentTab on tab 0.
So, using the suggestions previously posted:
android:noHistory="true" on the Splash activity
calling Splash.this.finish() after it launches the Home TabActivity
setting the Home TabActivity intent flag of Intent.FLAG_ACTIVITY_CLEAR_TOP
setting the Home TabActivity intent flag of Intent.FLAG_ACTIVITY_NO_HISTORY
The users sees the splash, the TabActivity launches, the user clicks to another tab, then hits back - the application closes (not force close - just closes back to the devices home screen).
If I don't use any of those, when the user hits back after changing to another tab, they go back to the Splash screen and are stuck (I could add a button or something to take them to the Home TabActivity but that's not optimal).
The desired result is that the user sees the Splash, gets taken to the Home TabActivity, clicks another tab, then hits back, he should be taken back to the initially set tab (tab 0).
Any insight is appreciated.
TYIA
The back stack is actually officially called the activity stack - every time you start an activity, that gets pushed onto the top of the stack (unless you set one of those flags you mentioned).
This means that unless each tab in your main app is a separate activity, then the default back key behaviour will be to leave your main app activity.
You can control this by taking over the back key or by overriding the tab switching behaviour to start different activities.