Android Open MainActivity after click back button in Notification Activity
up vote
1
down vote
favorite
I am developing one application, which will show a list of Card View inside a Recycler view in MainActivity. While clicking the Card view it will launch different activity. The flow is
SplashScreenActivity -> MainActivity(Recycler View) -> DetailsActivity
The flow is working fine if we launch the application by clicking app icon.
As part of this app, I am sending FCM notifications to the app. Whenever notification is received DetailsActivity will be launched, during that time MainActivity will not be in the stack. I am staring the MainActivity whenever backbutton of Details Activity is being pressed.If DetailsActivity is not called from Notification then I am not calling MainActivity again.
Below is the code snippet I have done to handle back button in Details Activity.
@Override
public void onBackPressed()
if (isFromNotification)
System.out.println("Start from Notification");
Intent intent = new Intent(this,MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
super.onBackPressed();
startActivity(intent);
else
System.out.println("Start from Normal Mode");
super.onBackPressed();
I have two issues here.
i) When FCM is received Notification is viewed in DetailsActivity. After pressing the back button MainActivity is launched and DetailsActivity is not killed. After Pressing the back button from MaainActivity again Details Activity is launched.
ii) Whenever MainActivity is launched by after receiving notification (By Clicking back button of Details Activity), recyclerview elements are not clickable.
I tried my best to explain the issue, your help is really appreciated !!!
android
add a comment |
up vote
1
down vote
favorite
I am developing one application, which will show a list of Card View inside a Recycler view in MainActivity. While clicking the Card view it will launch different activity. The flow is
SplashScreenActivity -> MainActivity(Recycler View) -> DetailsActivity
The flow is working fine if we launch the application by clicking app icon.
As part of this app, I am sending FCM notifications to the app. Whenever notification is received DetailsActivity will be launched, during that time MainActivity will not be in the stack. I am staring the MainActivity whenever backbutton of Details Activity is being pressed.If DetailsActivity is not called from Notification then I am not calling MainActivity again.
Below is the code snippet I have done to handle back button in Details Activity.
@Override
public void onBackPressed()
if (isFromNotification)
System.out.println("Start from Notification");
Intent intent = new Intent(this,MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
super.onBackPressed();
startActivity(intent);
else
System.out.println("Start from Normal Mode");
super.onBackPressed();
I have two issues here.
i) When FCM is received Notification is viewed in DetailsActivity. After pressing the back button MainActivity is launched and DetailsActivity is not killed. After Pressing the back button from MaainActivity again Details Activity is launched.
ii) Whenever MainActivity is launched by after receiving notification (By Clicking back button of Details Activity), recyclerview elements are not clickable.
I tried my best to explain the issue, your help is really appreciated !!!
android
for first issue you can just add a finish(); after starting the mainactivity in your if condition. It will kill the detailsActivity on backpressed. For second issue, we might need more details on code or xml file to look into.
– ManishPrajapati
Nov 11 at 6:21
added finish() method,once i presses the back button in MainActivity the application is available in the application tray (where you can find list of runnning / minimized apps) once I click my application it is launching the Details Activity.
– Jegan
Nov 11 at 6:30
For the second issue I have a fragment on top of MainActivity. That fragment is holding the recycler view
– Jegan
Nov 11 at 6:33
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I am developing one application, which will show a list of Card View inside a Recycler view in MainActivity. While clicking the Card view it will launch different activity. The flow is
SplashScreenActivity -> MainActivity(Recycler View) -> DetailsActivity
The flow is working fine if we launch the application by clicking app icon.
As part of this app, I am sending FCM notifications to the app. Whenever notification is received DetailsActivity will be launched, during that time MainActivity will not be in the stack. I am staring the MainActivity whenever backbutton of Details Activity is being pressed.If DetailsActivity is not called from Notification then I am not calling MainActivity again.
Below is the code snippet I have done to handle back button in Details Activity.
@Override
public void onBackPressed()
if (isFromNotification)
System.out.println("Start from Notification");
Intent intent = new Intent(this,MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
super.onBackPressed();
startActivity(intent);
else
System.out.println("Start from Normal Mode");
super.onBackPressed();
I have two issues here.
i) When FCM is received Notification is viewed in DetailsActivity. After pressing the back button MainActivity is launched and DetailsActivity is not killed. After Pressing the back button from MaainActivity again Details Activity is launched.
ii) Whenever MainActivity is launched by after receiving notification (By Clicking back button of Details Activity), recyclerview elements are not clickable.
I tried my best to explain the issue, your help is really appreciated !!!
android
I am developing one application, which will show a list of Card View inside a Recycler view in MainActivity. While clicking the Card view it will launch different activity. The flow is
SplashScreenActivity -> MainActivity(Recycler View) -> DetailsActivity
The flow is working fine if we launch the application by clicking app icon.
As part of this app, I am sending FCM notifications to the app. Whenever notification is received DetailsActivity will be launched, during that time MainActivity will not be in the stack. I am staring the MainActivity whenever backbutton of Details Activity is being pressed.If DetailsActivity is not called from Notification then I am not calling MainActivity again.
Below is the code snippet I have done to handle back button in Details Activity.
@Override
public void onBackPressed()
if (isFromNotification)
System.out.println("Start from Notification");
Intent intent = new Intent(this,MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
super.onBackPressed();
startActivity(intent);
else
System.out.println("Start from Normal Mode");
super.onBackPressed();
I have two issues here.
i) When FCM is received Notification is viewed in DetailsActivity. After pressing the back button MainActivity is launched and DetailsActivity is not killed. After Pressing the back button from MaainActivity again Details Activity is launched.
ii) Whenever MainActivity is launched by after receiving notification (By Clicking back button of Details Activity), recyclerview elements are not clickable.
I tried my best to explain the issue, your help is really appreciated !!!
android
android
asked Nov 11 at 6:15
Jegan
82
82
for first issue you can just add a finish(); after starting the mainactivity in your if condition. It will kill the detailsActivity on backpressed. For second issue, we might need more details on code or xml file to look into.
– ManishPrajapati
Nov 11 at 6:21
added finish() method,once i presses the back button in MainActivity the application is available in the application tray (where you can find list of runnning / minimized apps) once I click my application it is launching the Details Activity.
– Jegan
Nov 11 at 6:30
For the second issue I have a fragment on top of MainActivity. That fragment is holding the recycler view
– Jegan
Nov 11 at 6:33
add a comment |
for first issue you can just add a finish(); after starting the mainactivity in your if condition. It will kill the detailsActivity on backpressed. For second issue, we might need more details on code or xml file to look into.
– ManishPrajapati
Nov 11 at 6:21
added finish() method,once i presses the back button in MainActivity the application is available in the application tray (where you can find list of runnning / minimized apps) once I click my application it is launching the Details Activity.
– Jegan
Nov 11 at 6:30
For the second issue I have a fragment on top of MainActivity. That fragment is holding the recycler view
– Jegan
Nov 11 at 6:33
for first issue you can just add a finish(); after starting the mainactivity in your if condition. It will kill the detailsActivity on backpressed. For second issue, we might need more details on code or xml file to look into.
– ManishPrajapati
Nov 11 at 6:21
for first issue you can just add a finish(); after starting the mainactivity in your if condition. It will kill the detailsActivity on backpressed. For second issue, we might need more details on code or xml file to look into.
– ManishPrajapati
Nov 11 at 6:21
added finish() method,once i presses the back button in MainActivity the application is available in the application tray (where you can find list of runnning / minimized apps) once I click my application it is launching the Details Activity.
– Jegan
Nov 11 at 6:30
added finish() method,once i presses the back button in MainActivity the application is available in the application tray (where you can find list of runnning / minimized apps) once I click my application it is launching the Details Activity.
– Jegan
Nov 11 at 6:30
For the second issue I have a fragment on top of MainActivity. That fragment is holding the recycler view
– Jegan
Nov 11 at 6:33
For the second issue I have a fragment on top of MainActivity. That fragment is holding the recycler view
– Jegan
Nov 11 at 6:33
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
The PendingIntent
you include in the notification shown by your FCM message can describe a backstack with your MainActivity below your DetailsActivity.
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addNextIntent(new Intent(context, MainActivity.class));
stackBuilder.addNextIntent(new Intent(context, DetailsActivity.class));
PendingIntent notificationIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
The PendingIntent
you include in the notification shown by your FCM message can describe a backstack with your MainActivity below your DetailsActivity.
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addNextIntent(new Intent(context, MainActivity.class));
stackBuilder.addNextIntent(new Intent(context, DetailsActivity.class));
PendingIntent notificationIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
add a comment |
up vote
0
down vote
accepted
The PendingIntent
you include in the notification shown by your FCM message can describe a backstack with your MainActivity below your DetailsActivity.
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addNextIntent(new Intent(context, MainActivity.class));
stackBuilder.addNextIntent(new Intent(context, DetailsActivity.class));
PendingIntent notificationIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
The PendingIntent
you include in the notification shown by your FCM message can describe a backstack with your MainActivity below your DetailsActivity.
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addNextIntent(new Intent(context, MainActivity.class));
stackBuilder.addNextIntent(new Intent(context, DetailsActivity.class));
PendingIntent notificationIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
The PendingIntent
you include in the notification shown by your FCM message can describe a backstack with your MainActivity below your DetailsActivity.
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addNextIntent(new Intent(context, MainActivity.class));
stackBuilder.addNextIntent(new Intent(context, DetailsActivity.class));
PendingIntent notificationIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
answered Nov 11 at 7:44
krage
312
312
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53246333%2fandroid-open-mainactivity-after-click-back-button-in-notification-activity%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
for first issue you can just add a finish(); after starting the mainactivity in your if condition. It will kill the detailsActivity on backpressed. For second issue, we might need more details on code or xml file to look into.
– ManishPrajapati
Nov 11 at 6:21
added finish() method,once i presses the back button in MainActivity the application is available in the application tray (where you can find list of runnning / minimized apps) once I click my application it is launching the Details Activity.
– Jegan
Nov 11 at 6:30
For the second issue I have a fragment on top of MainActivity. That fragment is holding the recycler view
– Jegan
Nov 11 at 6:33