whenever i am pressing my positive button of alert dialog by simply writing toast it is working fine and toast is visible but if i am performing any action on positive button then the action is getting performed but in the meanwhile my app also crashes.
In my app basically after clicking positive button it has to send on link of forgotten password to respective mail id.
code is working fine for sending link of forgotten password.
whenever i am pressing positive button of alert dialogue i am able to get the link in my mail but i don't know why my app crashes just after hitting the positive button of alert dialogue
disire:- I just want to run my app smoothly that is after pressing positive button it should show the required toast message and just close the alert dialogue by performing the required action.
below is the error shown in logcat.
java.lang.RuntimeException: Performing stop of activity that is not resumed:
{com.android.launcher3/com.android.launcher2.Launcher}
code snippet is like this.
sendingPassword=FirebaseAuth.getInstance();
AlertDialog.Builder builder=new AlertDialog.Builder(getActivity());
LayoutInflater inflater=getActivity().getLayoutInflater();
final View view=inflater.inflate(R.layout.dialogue_layout,null);
builder.setView(view)
.setTitle("forget password")
.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
}
})
.setPositiveButton("send", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
forgetEmail=view.findViewById(R.id.forgetpasswordarea);
sendingPassword.sendPasswordResetEmail(forgetEmail.getText().toString().trim())
.addOnCompleteListener(new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task) {
if(task.isSuccessful())
{
Toast.makeText(getActivity(),"check your email for link",Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(getActivity(),task.getException().getMessage(),Toast.LENGTH_LONG).show();
}
}
});
}
});
return builder.create();
}
Related
public void exit(){
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setIcon(R.mipmap.ic_launcher_round);
builder.setTitle("Likee Likes");
builder.setMessage("Do you really wanna Exit?")
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
builder.create();
builder.show();
}
**I am using this code to confirm my user either exit or not. when my user click the "yes" button the app doesn't close and get back to the previous activity. Is there any mistake with this code? **
i am trying to close my app by user confirmation.
I assumes you use AlertDialog in the another activity rather than your first activity, so when you use finish, you are close the activity that isn't the first activity.
If you you want to close you app, you can try use startActivityForResult to process some job accordingto the requestCode.
But now startActivityForResult is deprected, you can try to use new way to do this: OnActivityResult method is deprecated, what is the alternative?.
You can reference to this too How to quit android application programmatically
I want to open a small popup or something like that on a button click such that the popup contains two buttons which on clicking goes to their corresponding activities.
Please provide the code as i am totally new to android?
Yes you can do this with Dialogs
use Below Code to make dialog:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
//Uncomment the below code to Set the message and title from the strings.xml file
//builder.setMessage(R.string.dialog_message) .setTitle(R.string.dialog_title);
//Setting message manually and performing action on button click
builder.setMessage("Do you want to close this application ?")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
finish();
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// Action for 'NO' Button
dialog.cancel();
}
});
//Creating dialog box
AlertDialog alert = builder.create();
//Setting the title manually
alert.setTitle("AlertDialogExample");
alert.show();
A dialog is a small window that prompts the user to make a decision or enter additional information. A dialog does not fill the screen and is normally used for modal events that require users to take an action before they can proceed.
find details of dialogs in below link:
Dialogs
You can use material alert dialog for this
Check this!
Initially in my app I am creating an AlertDialog which has three buttons, in which the middle button opens up another AlertDialog. The problem is that when the second AlertDialog closes after a button is pressed, the first one closes with it. I think both AlertDialogs get closed after I press a button on the second AlertDialog.
What I want is for the first AlertDialog to open another AlertDialog that has its own buttons, and when second AlertDialog presses a button, it only closes itself and goes back to the first one. Is there any way to achieve this?
Here is the code for the button used to open the AlertDialog:
final ImageButton fabgroup = (ImageButton) findViewById(R.id.groupButton);
Here's the code for a button that opens an AlertDialog that contains another button that opens another AlertDialog using the middle button (create button) on itself, but closes them both when a button on the second one is pressed (either the yes or no button, which is not what I want as I only want the second one to close itself and go back to the first AlertDialog, and yea this sounds pretty confusing in theory so I can try to clarify if needed):
fabgroup.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
final AlertDialog.Builder helpBuilder = new AlertDialog.Builder(CreateNote.this);
helpBuilder.setTitle("Select a group");
helpBuilder.setMessage("Add to group?");
final TextView input = new TextView(mainactiv.this);
input.setSingleLine();
input.setText("");
helpBuilder.setView(input);
helpBuilder.setNegativeButton("Yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Do nothing but close the dialog
Toast.makeText(CreateNote.this, "Page has been added to group", Toast.LENGTH_SHORT).show();
}
});
helpBuilder.setNeutralButton("Create", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
//open another alertbox
AlertDialog.Builder helpBuilder2 = new AlertDialog.Builder(CreateNote.this);
helpBuilder2.setTitle("Assign a new group");
helpBuilder2.setMessage("Create group?");
final EditText input = new EditText(CreateNote.this);
input.setSingleLine();
input.setText("");
helpBuilder2.setView(input);
helpBuilder2.setNegativeButton("Yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Create Group
Toast.makeText(CreateNote.this, "Group has been created", Toast.LENGTH_SHORT).show();
}
});
helpBuilder2.setPositiveButton("No", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
// Do nothing
}
});
// Remember, create doesn't show the dialog
AlertDialog helpDialog2 = helpBuilder2.create();
helpDialog2.show();
}
});
helpBuilder.setPositiveButton("No", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
// Do nothing
}
});
// Remember, create doesn't show the dialog
AlertDialog helpDialog = helpBuilder.create();
helpDialog.show();
}
});
Help would be greatly appreciated.
I eventually managed to solve this problem by creating two separate functions to generate each dialog box, and when one closes it calls the function to create the other one, kinda like recycling (or maybe closer to looping functions). Although, I'm not entirely sure how performance heavy this is, but it seems to do the job without any issues from what I'm testing. If anyone would like to chime in on how this could be an issue, then I'm open to hearing what others have to say about the negative points of using alert dialog boxes this way.
You can show an activity as dialog. Put this in your manifest file.
<activity android:theme="#android:style/Theme.Dialog" android:excludeFromRecents="true"/>
From this answer: Android Activity as a dialog
Following... this link ..How to set image as wall paper in viewpager app?. I am able to set wallpaper directly located in my drawable folder. However, i want to give user a chance to set wallpaper by displaying pop up dialogue box which should be displayed. When user clicks on images for 3-5 sec.
I am kind of new to android programming.. So, please help..
android framework already supporting class "alertDialogue.builder". you can set message whatever you wanna show in addition to dialogue buttons, title etc.
http://developer.android.com/reference/android/app/AlertDialog.Builder.html
5sec is too long to stay in one fingerpoint. in onsimplegesturedetector class, there is already "long press" detector
http://developer.android.com/reference/android/view/GestureDetector.SimpleOnGestureListener.html
you can set your own ontouchListener that implements onTouchListener that has gesture detector, detects long press and can show dialogue .
there can be better way but I'm using this logic in my project so you can reference and fix it if you find better way
findViewById("your wall paper image id").onTouchListener(new MyOnTouchListener());
class MyOnTouchListener implements onTouchListener{
GestureDetector gd = new GestureDetector(new SimpleOnGestureListener(){
#Override
public void onLongPress(MotionEvent e) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
context);
alertDialogBuilder.setTitle("Your Title");
alertDialogBuilder
.setMessage("click yes to set wallpaper!")
.setCancelable(false)
.setPositiveButton("Yes",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
//setting wallpaper
}
})
.setNegativeButton("No",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
dialog.cancel();
}
});
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
}
});
}
I am new to Android I am developing an application in API level 2.2.
In my application whenever I press Home button it forces my app to exit. When I relaunch that app by clicking on its icon, it starts from where it exited.
I used CountDownTimer in my application and what i want is showing an Alert Dialog when relaunched.
protected void onResume()
{
AlertDialog.Builder alertDialog = new AlertDialog.Builder(StartActivity.this);
alertDialog.setMessage("Resume Current Excersize ?");
alertDialog.setPositiveButton("OK",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int which)
{
startCounterTime();//my method
....
}
});
alertDialog.show();
}