Creating Alert Dialog and Making Notification Gives the Error: Unable to Add Window











up vote
0
down vote

favorite












I'd first like to state that this is not a duplicate of the "Unable to Add Window" error problem that others were receiving with Alert Dialogs. What this app does is create a notification and Alert Dialog when a value is added to a certain path in Firebase. I tested the notification and Alert Dialog individually and they were working. Even when the app was in the background, I didn't get any errors.



The problem "Unable to Add Window" came when I tried tapping on the notification to take me back to my app. The way that my app functions is that on another device, a button is pressed and it inserts some values into Firebase under two paths, one for notifications, and another for the Alert Dialog. Then, on my current device, it reads from those paths to check if they are not empty. If they aren't empty, then it will create a notification and the Alert Dialog.



Current behavior: What is happening right now, is that the notification and Alert Dialog appear in the activity. The notification also pops up when I am in another app as long as my app is in the background. The problem comes when I press on the notification to take me back to my app. It does take me to the activity, as expected, but when the new values are inserted into Firebase, it gives me the "Unable to Add Window" error.



I am unable to figure out why this error is occurring because the Alert Dialog and notification work fine in the app, but when I use the notification to go to the app, I get this error. I have tried reading other StackOverflow answers for the same "Unable to add Window" error, but none of those solutions have worked for me because they had to do with the context of the Alert Dialog, whereas here my problem is with the notification taking me back to my app.



This is the link to my full Java code on GitHub.
Here is the function which I call to create a notification:



private void makeNotification(DatabaseReference databaseReference102, String value) {
// The error occurs when I click on the notification to take me back to the app which is in the code below.
//When I click on the notification, the next time values are aded to Firebase, it gives me the "Unable to Add Window" error.
Intent intent = new Intent(getApplicationContext(), CaretakerAccount.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getApplicationContext(), "Channel")
.setSmallIcon(R.drawable.notification)
.setContentTitle("A User Logged In!")
.setContentText(value + " just logged in!")
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(value + " just logged in!"))
.setContentIntent(pendingIntent)
.setAutoCancel(true)
.setPriority(NotificationCompat.PRIORITY_MAX);

NotificationManagerCompat notificationManager = NotificationManagerCompat.from(getApplicationContext());

notificationManager.notify(0, mBuilder.build());
databaseReference102.removeValue();
//Removes the value in the notification path that way the notification is not made repeatedly.
}


Any and all help is appreciated. Thanks in advance!










share|improve this question




















  • 1




    If you could rather add some useful and small amount of code in which you think problem might be, it'd be helpful.
    – PradyumanDixit
    Nov 8 at 4:08










  • I think the problem is with clicking on the notification to go to the app. This is on lines 212- 235 at the link over here
    – Ishaan
    Nov 8 at 4:09






  • 1




    Please don't just link to your project off-site. You need to include a Minimal, Complete, and Verifiable example in the question itself.
    – Mike M.
    Nov 8 at 4:12










  • Ok. I added the function which is used to make the notification which is probably where the problem occurs.
    – Ishaan
    Nov 8 at 4:13










  • @PradyumanDixit do you have any ideas for why I am getting this error. At this point, I am very certain that the error is with the notification, but I am not able to figure out why when I press it, it is not able to create the Alert Dialog.
    – Ishaan
    Nov 8 at 4:49















up vote
0
down vote

favorite












I'd first like to state that this is not a duplicate of the "Unable to Add Window" error problem that others were receiving with Alert Dialogs. What this app does is create a notification and Alert Dialog when a value is added to a certain path in Firebase. I tested the notification and Alert Dialog individually and they were working. Even when the app was in the background, I didn't get any errors.



The problem "Unable to Add Window" came when I tried tapping on the notification to take me back to my app. The way that my app functions is that on another device, a button is pressed and it inserts some values into Firebase under two paths, one for notifications, and another for the Alert Dialog. Then, on my current device, it reads from those paths to check if they are not empty. If they aren't empty, then it will create a notification and the Alert Dialog.



Current behavior: What is happening right now, is that the notification and Alert Dialog appear in the activity. The notification also pops up when I am in another app as long as my app is in the background. The problem comes when I press on the notification to take me back to my app. It does take me to the activity, as expected, but when the new values are inserted into Firebase, it gives me the "Unable to Add Window" error.



I am unable to figure out why this error is occurring because the Alert Dialog and notification work fine in the app, but when I use the notification to go to the app, I get this error. I have tried reading other StackOverflow answers for the same "Unable to add Window" error, but none of those solutions have worked for me because they had to do with the context of the Alert Dialog, whereas here my problem is with the notification taking me back to my app.



This is the link to my full Java code on GitHub.
Here is the function which I call to create a notification:



private void makeNotification(DatabaseReference databaseReference102, String value) {
// The error occurs when I click on the notification to take me back to the app which is in the code below.
//When I click on the notification, the next time values are aded to Firebase, it gives me the "Unable to Add Window" error.
Intent intent = new Intent(getApplicationContext(), CaretakerAccount.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getApplicationContext(), "Channel")
.setSmallIcon(R.drawable.notification)
.setContentTitle("A User Logged In!")
.setContentText(value + " just logged in!")
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(value + " just logged in!"))
.setContentIntent(pendingIntent)
.setAutoCancel(true)
.setPriority(NotificationCompat.PRIORITY_MAX);

NotificationManagerCompat notificationManager = NotificationManagerCompat.from(getApplicationContext());

notificationManager.notify(0, mBuilder.build());
databaseReference102.removeValue();
//Removes the value in the notification path that way the notification is not made repeatedly.
}


Any and all help is appreciated. Thanks in advance!










share|improve this question




















  • 1




    If you could rather add some useful and small amount of code in which you think problem might be, it'd be helpful.
    – PradyumanDixit
    Nov 8 at 4:08










  • I think the problem is with clicking on the notification to go to the app. This is on lines 212- 235 at the link over here
    – Ishaan
    Nov 8 at 4:09






  • 1




    Please don't just link to your project off-site. You need to include a Minimal, Complete, and Verifiable example in the question itself.
    – Mike M.
    Nov 8 at 4:12










  • Ok. I added the function which is used to make the notification which is probably where the problem occurs.
    – Ishaan
    Nov 8 at 4:13










  • @PradyumanDixit do you have any ideas for why I am getting this error. At this point, I am very certain that the error is with the notification, but I am not able to figure out why when I press it, it is not able to create the Alert Dialog.
    – Ishaan
    Nov 8 at 4:49













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I'd first like to state that this is not a duplicate of the "Unable to Add Window" error problem that others were receiving with Alert Dialogs. What this app does is create a notification and Alert Dialog when a value is added to a certain path in Firebase. I tested the notification and Alert Dialog individually and they were working. Even when the app was in the background, I didn't get any errors.



The problem "Unable to Add Window" came when I tried tapping on the notification to take me back to my app. The way that my app functions is that on another device, a button is pressed and it inserts some values into Firebase under two paths, one for notifications, and another for the Alert Dialog. Then, on my current device, it reads from those paths to check if they are not empty. If they aren't empty, then it will create a notification and the Alert Dialog.



Current behavior: What is happening right now, is that the notification and Alert Dialog appear in the activity. The notification also pops up when I am in another app as long as my app is in the background. The problem comes when I press on the notification to take me back to my app. It does take me to the activity, as expected, but when the new values are inserted into Firebase, it gives me the "Unable to Add Window" error.



I am unable to figure out why this error is occurring because the Alert Dialog and notification work fine in the app, but when I use the notification to go to the app, I get this error. I have tried reading other StackOverflow answers for the same "Unable to add Window" error, but none of those solutions have worked for me because they had to do with the context of the Alert Dialog, whereas here my problem is with the notification taking me back to my app.



This is the link to my full Java code on GitHub.
Here is the function which I call to create a notification:



private void makeNotification(DatabaseReference databaseReference102, String value) {
// The error occurs when I click on the notification to take me back to the app which is in the code below.
//When I click on the notification, the next time values are aded to Firebase, it gives me the "Unable to Add Window" error.
Intent intent = new Intent(getApplicationContext(), CaretakerAccount.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getApplicationContext(), "Channel")
.setSmallIcon(R.drawable.notification)
.setContentTitle("A User Logged In!")
.setContentText(value + " just logged in!")
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(value + " just logged in!"))
.setContentIntent(pendingIntent)
.setAutoCancel(true)
.setPriority(NotificationCompat.PRIORITY_MAX);

NotificationManagerCompat notificationManager = NotificationManagerCompat.from(getApplicationContext());

notificationManager.notify(0, mBuilder.build());
databaseReference102.removeValue();
//Removes the value in the notification path that way the notification is not made repeatedly.
}


Any and all help is appreciated. Thanks in advance!










share|improve this question















I'd first like to state that this is not a duplicate of the "Unable to Add Window" error problem that others were receiving with Alert Dialogs. What this app does is create a notification and Alert Dialog when a value is added to a certain path in Firebase. I tested the notification and Alert Dialog individually and they were working. Even when the app was in the background, I didn't get any errors.



The problem "Unable to Add Window" came when I tried tapping on the notification to take me back to my app. The way that my app functions is that on another device, a button is pressed and it inserts some values into Firebase under two paths, one for notifications, and another for the Alert Dialog. Then, on my current device, it reads from those paths to check if they are not empty. If they aren't empty, then it will create a notification and the Alert Dialog.



Current behavior: What is happening right now, is that the notification and Alert Dialog appear in the activity. The notification also pops up when I am in another app as long as my app is in the background. The problem comes when I press on the notification to take me back to my app. It does take me to the activity, as expected, but when the new values are inserted into Firebase, it gives me the "Unable to Add Window" error.



I am unable to figure out why this error is occurring because the Alert Dialog and notification work fine in the app, but when I use the notification to go to the app, I get this error. I have tried reading other StackOverflow answers for the same "Unable to add Window" error, but none of those solutions have worked for me because they had to do with the context of the Alert Dialog, whereas here my problem is with the notification taking me back to my app.



This is the link to my full Java code on GitHub.
Here is the function which I call to create a notification:



private void makeNotification(DatabaseReference databaseReference102, String value) {
// The error occurs when I click on the notification to take me back to the app which is in the code below.
//When I click on the notification, the next time values are aded to Firebase, it gives me the "Unable to Add Window" error.
Intent intent = new Intent(getApplicationContext(), CaretakerAccount.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getApplicationContext(), "Channel")
.setSmallIcon(R.drawable.notification)
.setContentTitle("A User Logged In!")
.setContentText(value + " just logged in!")
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(value + " just logged in!"))
.setContentIntent(pendingIntent)
.setAutoCancel(true)
.setPriority(NotificationCompat.PRIORITY_MAX);

NotificationManagerCompat notificationManager = NotificationManagerCompat.from(getApplicationContext());

notificationManager.notify(0, mBuilder.build());
databaseReference102.removeValue();
//Removes the value in the notification path that way the notification is not made repeatedly.
}


Any and all help is appreciated. Thanks in advance!







android firebase firebase-realtime-database notifications alertdialog






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 13:19

























asked Nov 8 at 4:04









Ishaan

6571316




6571316








  • 1




    If you could rather add some useful and small amount of code in which you think problem might be, it'd be helpful.
    – PradyumanDixit
    Nov 8 at 4:08










  • I think the problem is with clicking on the notification to go to the app. This is on lines 212- 235 at the link over here
    – Ishaan
    Nov 8 at 4:09






  • 1




    Please don't just link to your project off-site. You need to include a Minimal, Complete, and Verifiable example in the question itself.
    – Mike M.
    Nov 8 at 4:12










  • Ok. I added the function which is used to make the notification which is probably where the problem occurs.
    – Ishaan
    Nov 8 at 4:13










  • @PradyumanDixit do you have any ideas for why I am getting this error. At this point, I am very certain that the error is with the notification, but I am not able to figure out why when I press it, it is not able to create the Alert Dialog.
    – Ishaan
    Nov 8 at 4:49














  • 1




    If you could rather add some useful and small amount of code in which you think problem might be, it'd be helpful.
    – PradyumanDixit
    Nov 8 at 4:08










  • I think the problem is with clicking on the notification to go to the app. This is on lines 212- 235 at the link over here
    – Ishaan
    Nov 8 at 4:09






  • 1




    Please don't just link to your project off-site. You need to include a Minimal, Complete, and Verifiable example in the question itself.
    – Mike M.
    Nov 8 at 4:12










  • Ok. I added the function which is used to make the notification which is probably where the problem occurs.
    – Ishaan
    Nov 8 at 4:13










  • @PradyumanDixit do you have any ideas for why I am getting this error. At this point, I am very certain that the error is with the notification, but I am not able to figure out why when I press it, it is not able to create the Alert Dialog.
    – Ishaan
    Nov 8 at 4:49








1




1




If you could rather add some useful and small amount of code in which you think problem might be, it'd be helpful.
– PradyumanDixit
Nov 8 at 4:08




If you could rather add some useful and small amount of code in which you think problem might be, it'd be helpful.
– PradyumanDixit
Nov 8 at 4:08












I think the problem is with clicking on the notification to go to the app. This is on lines 212- 235 at the link over here
– Ishaan
Nov 8 at 4:09




I think the problem is with clicking on the notification to go to the app. This is on lines 212- 235 at the link over here
– Ishaan
Nov 8 at 4:09




1




1




Please don't just link to your project off-site. You need to include a Minimal, Complete, and Verifiable example in the question itself.
– Mike M.
Nov 8 at 4:12




Please don't just link to your project off-site. You need to include a Minimal, Complete, and Verifiable example in the question itself.
– Mike M.
Nov 8 at 4:12












Ok. I added the function which is used to make the notification which is probably where the problem occurs.
– Ishaan
Nov 8 at 4:13




Ok. I added the function which is used to make the notification which is probably where the problem occurs.
– Ishaan
Nov 8 at 4:13












@PradyumanDixit do you have any ideas for why I am getting this error. At this point, I am very certain that the error is with the notification, but I am not able to figure out why when I press it, it is not able to create the Alert Dialog.
– Ishaan
Nov 8 at 4:49




@PradyumanDixit do you have any ideas for why I am getting this error. At this point, I am very certain that the error is with the notification, but I am not able to figure out why when I press it, it is not able to create the Alert Dialog.
– Ishaan
Nov 8 at 4:49

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53201407%2fcreating-alert-dialog-and-making-notification-gives-the-error-unable-to-add-win%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53201407%2fcreating-alert-dialog-and-making-notification-gives-the-error-unable-to-add-win%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Xamarin.form Move up view when keyboard appear

JBPM : POST request for execute process go wrong