OK Dialog in android - android

I have an activity that starts on demand of the user.
The user can demand it from several activities.
The thing is I want to give the user an explanation before he has to handle that activity.
I thought about creating a Dialog, giving the user only an OK button to tap on.
But It will be ugly because:
It has to return a value (in my case there is no value I have to return)
The Dialog will have to start the new activity, then when the user presses 'back' button, it will return to the Dialog
Also, if I choose to return to the activity that showed the dialog and start the new activity from there, I'll have to do this in several places (like I explained in the second line of this questions)
Any ideas?
Thanks!

Not sure what you mean by 1. but if you call dismiss() in the onClickListener that handles your OK button, it will not be shown again after you come back from the started activity when you press the back button.
Do make it easier to reuse the dialog, you should create a custom class that handles the dialog. Then you can easily show the dialog from different activities.

Related

How to access KeyChain.choosePrivateKeyAlias activity?

The following method:KeyChain.choosePrivateKeyAlias creates system dialog which allows user to choose a key alias from a list. As one of the arguments it takes Activity context which will be used to spawn this dialog. When selection is made it will call a callback.
In my scenario user doesn't select any alias but presses "Home" button. I would like to intercept this event. How can I do that?
Also I would like to cancel this dialog programatically. In this case I need some way to access this child Activity (please note that choosePrivateKeyAlias doesn't return any "handle" to the new dialog). Is it possible to access child Activity without any references (handle/id/etc.) to it?
There is no way to programatically end that activity because it is a system activity. It's the same as launching the browser on your device or the contact list. The only way to exit it is to press back and it will close that activity and resume yours.
According to my understanding, if you want to dismiss that dialog. Then as far as I know about Android OS. There are lifecycle methods for Activity. So I think
IF YOU CALL "yourDailog.dismiss()" INSIDE YOUR ACTIVITY's "onStop()". SO YOUR PROBLEM WILL BE SOLVED
If you do it in above way, so whenever you press HOME button, It will call onStop method of your activity. At that time, It will dismiss that dialog.

onBackpressed DialogFragment

I have 3 custom dialogs (DialogFragment). All are not cancelable, because it is necessary, that the user can't close them. The first dialog starts the second, and the second the third. Now I want to came back to the previous dialog, if I'm using the backclick. At this moment I have two options, but both are not work's really fine:
I start from one dialog the new one, but never call the dismiss. -> So in the background of the next dialog is always the view of the previous dialog
I call dismiss, if I'm start the next dialog, but then he will not return to the previous dialog, but close the dialog.
What can I do, to start the new dialog, so, that the first one is not visible, but if I'm click back, the dialog is visible again?
Thanks a lot for help :))
When you advance from second dialog to third you can close the second one so that you don't see it in the third one.
Later if you need to go back to the second dialog you can re-start it just before closing the third one, the same way you start it when you go from the first dialog to second dialog.
In order to override onBackPressed of a dialog you need to do something like this:
dialog.setOnCancelListener(new DialogInterface.OnCancelListener()
{
#Override
public void onCancel(DialogInterface dialog)
{
// OVERRIDE CODE
}
});
so the work flow would be something like this
firstDialog -> startSecondDialog
firstDialog.dismiss
secondDialog -> startThirdDialog
secondDialog.dismiss
and then if you need to go back you do:
thirdDialog -> startSecondDialog
thirdDialog.dismiss
and so on until you get back to the first dialog.
I hope this makes sense to you, and if not please give us some code so we can help with more details related to your project :)

How to show alert Dialog when home button is pressed ?(ICS)

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.

Maintain Single instance of an activity

i have button in my first activity called Start.
Now when i click on this button it takes 1 to 2 seconds to load the next activity, now at that time the user clicks on the start button multiple times so what happens is that the next activity will open multiple times.
How to overcome this? Is there any way that even if the user clicks on the Start button multiple times open the activity only once.
Your Options:
On click, disable the button and display a ProgressDialog to the user.
Use the Intent flag FLAG_ACTIVITY_SINGLE_TOP to ensure only one activity is maintained on the stack. Documentation
Use the qualifer launchMode=singleInstance in your AndroidManifest.xml so only one instance of your Activity is allowed at a time. Documentation
I would recommend the first, because it can show the user your application is still working even if it takes a few seconds to do the necessary processing to begin your Activity.
You can put the launch mode of your 2nd activity as "Single Instance" in your manifest file.
Don't use anything like a launchMode or Intent flags. They are used for different purposes.
Description here
What you have to do is:
Show a progress dialog to clearly show the user that an
action(calling 2nd Activity) is in progress. This was user will not
try to click the button multiple times
Simply disable the button's click listener after 1st click. This is not
recommended because user might not be able to know whether he/she
clicked the button. Also this is the case where user tends to click
the button multiple times.

Which function I have to call on a Cancel button in a user interface (activity)?

I have various activitys on my app. I have a configuration Activity, and I want to put a cancel button, that, when user press this button, the configuration window get's closed and turn back into the previous activity.
I found something about calling cancel or dismiss functions, but I can't call them cause this is not a dialog, it's an activity.
You can finish an activity.

Categories

Resources