Android: how to start Activity from warning dialog

I need to start an action when the user selects an item in the warning dialog. How to get the context for going to the intent constructor in the following code ...

builder.setItems(items, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { Intent i = new Intent(<WHAT DO I PUT HERE?>, <new activity>.class); startActivity(i); } }); 

Is this using an inner class? Any thoughts?

+4
source share
2 answers

You can get the context you passed in to AlertDialog.Builder using getBaseContext() . See the document here .

So this should work:

 Intent i = new Intent(getBaseContext(), <new activity>.class); startActivity(i); 
+6
source
 Intent i = new Intent("some.thing.activity"); startActivity(i); 

// in brackets you can add an activity path, that is: package name // for example: za.ac.cut.Activity

0
source

All Articles