I want to show an Alert Dialog via AlertDialogManager
class to a non-activity
class DeviceAdminReceiverSample
\'s method onDisabl
Here's a quick method of properly performing this task that has done the job for me. Basically, what you would do is just create a new thread.
Declare a public and static variable with a type that matches the original activity class.
public static Activity1 activity;
Activity1 is the class that the variable resides in.
Example:
@Override
protected void onCreate( Bundle savedInstanceState ) {
super.onCreate( savedInstanceState );
activity = this;
}
new Runnable()
for the runnable action required for runOnUiThread();
, and to have the alert dialog actually open, we would override the run function of a runnable item and place the code for the alert dialog in there.
Example function:
public static void exampleDialog(){
Activity1.activity.runOnUiThread(new Runnable){
@Override
public void run(){
//alert dialog code goes here. For the context, use the activity variable from Activity1.
}
}
}
Hope this helps :)