Problem Description
I'm using Native Screen Recording functionality provided by Android. When I start recording System popups Dialog and ask user to confirm that screen can be recorder. If user press outside dialog dismissed (same behaviour when he/she press cancel) when press Start Now Recording Start.
Question
How I can detect what user pressed
Cancel
Start Now
Dismissed on press outside
How can I disable dismiss on press outside of dialog
Is there a way to avoid showing dialog?
Screenshot
How I can detect what user pressed
You can determine if the user pressed "Start Now" as part of your normal media projection flow. For example, when you pass the onActivityResult() data to getMediaProjection(), getMediaProjection() will only give you a MediaProjection object if the user pressed "Start Now".
You cannot distinguish between "Cancel", "click outside the dialog", pressing the BACK button, pressing Esc on a device with a physical keyboard, or any other means of dismissing this dialog.
How can I disable dismiss on press outside of dialog
The decision on how to handle this is up to the system, not you.
Is there a way to avoid showing dialog?
No.
Related
I have an app with multiple Activity classes. In one part, one is a main screen and the next is a login. The user would open the login screen and enter their info and press a button to submit it. The resulting code opens up an AlertDialog to tell them the registration status, along with some other information. If the registration itself was successful, they will return to the previous activity. But this makes any AlertDialog disappear with it.
I want the background to return to the previous activity so they can see the home page start updating, but I want them to see the alert message long enough to read it.
Yes this is possble. By using a service you can display an alertbox which runs in foreground for a long time. I have done thissame kind of thing for a news app.
It will run in foreground for a long time and when you want to switch you can stop the service than it will dismiss the alert box-.
In my case I displayed a custom view with buttons in the foreground.
I want to show alert when user presses home button on device(do you want to exit the app ?)
How to do it ?
You can't handle Home button click, because of Android policy (Home button click event handling android). Of course, you can use onPause()/onStop() method of your current Activity, but your application will be moved to background too quick and user will not see your dialog, I think.
Also, note that Home not closes the app - just moves to background. User usually close app by pressing Back on main activity, try to handle it:
#Override
public void onBackPressed() {
// your dialog here
}
Is is not possible for Android apps to override the functionality of the home button. The best you can do is show the dialog when the user presses back in your topmost Activity.
You can find more information at the following SO answers:
https://stackoverflow.com/a/7240268/3214339
Android Overriding home key
Write the show alert dialog code in onPause() it will work perfectly.
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 have a timer which runs continously. When I press the BACK button I made a dialog to appear where you can quit from that intent or go back and cointinue the timer what has been stopped by the BACK button. Well if I click on the contimnue, the onResume() method makes the timer continue and it works good. But, if I press the back button when the dialog is on the screen I want the timer to go on just like if I press the Continue on the dialog. But instead, I press the back button and nothing happens, the timer is stopped and it is not good for me since some of my methods only works if the timer is going or it is stopped by the dialog. But if there is no dialog and the timer is stopped numerous potential errors can happen. So how can I stop the user to press the back button when the dialog is on the screen?
I tried something like this:
if ((keycode==back) && a=0 ) {... a=1 , onPuase()} // dialog comes in onPause() just happened
else ((keycode==back) && a=1 ) {... a=0, onResume()} //I want onResume() to happen here
But it is not good. The dialog appears on the first Back button then it disappears on the second Back (nothing happens here). The timer is still stopped here however the third back button starts the timer. So there is an unecessary Back which can cause troubles since the useres wont know that they have to press it again...
A few advices:
Do not call onResume/onPause manually, only system should make it. Else you'll have unexplainable issues on various devices.
You really want to use OnDismissListener ( http://developer.android.com/reference/android/content/DialogInterface.OnDismissListener.html ). As starting from ICS, dialog can be dismissed not only by pressing Back key, but also by tapping somewhere on screen, outside the dialog.
If you want to prevent dismissing the dialog by "back" and "tapping out of dialog" - use setCancellable(false) http://developer.android.com/reference/android/app/Dialog.html#setCancelable(boolean) for the dialog.
Good luck
If you want to be notified when user pressed BACK while your dialog was displayed, use OnDismissListener
implement OnDismissListener in your DialogClass
and override OnDismiss method
#Override
public void onDismiss(DialogInterface dialog) {
super.onDismiss(dialog);
//you can control back button from here
}
I've such situation:
By clicking on button from activity we should open browser, and finish activity.
But, if the user has more then one browser Complete Action Using dialog is showing, so user can complete action by choice or return to application by pressing back.
I should finish activity only in case that browser opened.
Is there any way do determine that intent delivered succefully?
Is there any to determine if Complete Action Dialog has been cancelled by pressing back?
If none of above, any suggestions reagards solving this problem?