Skip to content Skip to sidebar Skip to footer

How To Launch An Activity From A Dialog?

Any ideas how to launch an activity and send a value from a dialog button? Here's what I have at the moment. Tried a number of variations but app crashes when the button is pressed

Solution 1:

Did you check that you have added the Profile.class in the manifest file like such:

<activityandroid:name=".Profile" />

Solution 2:

On the button's onClick, I believe you need to startactivity and set the intent using the new activity and also reference it in the AndroidManifest.xml

Solution 3:

I ended up having to restructure the code, here is what ended up working:

AlertDialog.Builderbuilder=newAlertDialog.Builder(mContext);
builder.setTitle(item.getTitle())
.setCancelable(true)
.setPositiveButton("View Details", newDialogInterface.OnClickListener() {
    publicvoidonClick(DialogInterface dialog, int id) {
        Intentintent=newIntent(mContext, Profile.class);
        intent.putExtra("id", item.getSnippet());
        mContext.startActivity(intent);
        }
    });
AlertDialogalert= builder.create();
alert.show();
returntrue;

Post a Comment for "How To Launch An Activity From A Dialog?"