Reputation: 11
I wanted to use "AlertDialog" to create pop-up window in Conversation Page, but system showed " Unable to add window".
Hi, I wanted to create a "Strong-Remind" function : The user could bookmark one particular contact / group, and his/her phone will vibrate for 5-10 seconds when the user receives the message sent by the particular contact/group.
In my design,the user can stop the vibrate when they click the "confirm "button in pop-up window, but it cannot be achieved, I tried to add this function in mobicomkit\src\main\java\com\applozic\mobicomkit\api\notification\NotificationService.java, the vibrator has been created and worked well, but the pop-up windown cannot be created.
public void warn(){
vibrator =
(Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
long[] pattern = {100, 400, 100, 400};
vibrator.vibrate(pattern, 2);
final AlertDialog.Builder builder2 = new AlertDialog.Builder(context);
builder2.setTitle("Warning")
.setMessage("You have one important message !")
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
vibrator.cancel();
}
})
.show();
}
Caused by: android.view.WindowManager$BadTokenException: Unable to add
window -- token null is not valid; is your activity running?
at android.view.ViewRootImpl.setView(ViewRootImpl.java:785)
at
android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:356)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:94)
at android.app.Dialog.show(Dialog.java:352)
Upvotes: 1
Views: 32
Reputation: 803
final AlertDialog.Builder builder2 = new AlertDialog.Builder(context);
This context you passed is not a valid context , you could try another.
Upvotes: 1