Open Activity on Notification Click - Intent flag issue
up vote
0
down vote
favorite
I am creating an Android app. I have set up the notification system to open a specific activity/class on notification click. When my App is totally closed and I send a notification and when I click on it opens the correct activity like this example:
App is not running > Notification comes in > Click on the notification > Activity_T opens.
BUT, when my app is running and I get a notification and when I click on it to open the Activity_T it doesn't it loads MainActivity instead.
The flags I use are the follow
Intent intent = new Intent(mContext, (Class<?>) activityToLaunch);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
intent.putExtra("tt", title);
intent.putExtra("bd", body);
mContext.startActivity(intent);
I want to open Activity_T on notification click either the app is running or not. How to force open Activity_T whenever I click on the notification.
android android-intent flags
|
show 4 more comments
up vote
0
down vote
favorite
I am creating an Android app. I have set up the notification system to open a specific activity/class on notification click. When my App is totally closed and I send a notification and when I click on it opens the correct activity like this example:
App is not running > Notification comes in > Click on the notification > Activity_T opens.
BUT, when my app is running and I get a notification and when I click on it to open the Activity_T it doesn't it loads MainActivity instead.
The flags I use are the follow
Intent intent = new Intent(mContext, (Class<?>) activityToLaunch);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
intent.putExtra("tt", title);
intent.putExtra("bd", body);
mContext.startActivity(intent);
I want to open Activity_T on notification click either the app is running or not. How to force open Activity_T whenever I click on the notification.
android android-intent flags
1
Can you post the manifest? or some activity tag code
– jitesh mohite
Nov 8 at 5:13
@jiteshmohite if you are referring to know the launch mode of the Activity_T it is android:launchMode="singleTask" and for Mainactivity there is no launchmode set
– LoveDroid
Nov 8 at 5:23
try this, intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP| Intent.FLAG_ACTIVITY_SINGLE_TOP);
– jitesh mohite
Nov 8 at 5:23
@jiteshmohite thank you, I have just tried it but didn't solve the issue.
– LoveDroid
Nov 8 at 5:28
Remove singleTask from menifest and see.
– jitesh mohite
Nov 8 at 5:30
|
show 4 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am creating an Android app. I have set up the notification system to open a specific activity/class on notification click. When my App is totally closed and I send a notification and when I click on it opens the correct activity like this example:
App is not running > Notification comes in > Click on the notification > Activity_T opens.
BUT, when my app is running and I get a notification and when I click on it to open the Activity_T it doesn't it loads MainActivity instead.
The flags I use are the follow
Intent intent = new Intent(mContext, (Class<?>) activityToLaunch);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
intent.putExtra("tt", title);
intent.putExtra("bd", body);
mContext.startActivity(intent);
I want to open Activity_T on notification click either the app is running or not. How to force open Activity_T whenever I click on the notification.
android android-intent flags
I am creating an Android app. I have set up the notification system to open a specific activity/class on notification click. When my App is totally closed and I send a notification and when I click on it opens the correct activity like this example:
App is not running > Notification comes in > Click on the notification > Activity_T opens.
BUT, when my app is running and I get a notification and when I click on it to open the Activity_T it doesn't it loads MainActivity instead.
The flags I use are the follow
Intent intent = new Intent(mContext, (Class<?>) activityToLaunch);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
intent.putExtra("tt", title);
intent.putExtra("bd", body);
mContext.startActivity(intent);
I want to open Activity_T on notification click either the app is running or not. How to force open Activity_T whenever I click on the notification.
android android-intent flags
android android-intent flags
asked Nov 8 at 4:32
LoveDroid
257
257
1
Can you post the manifest? or some activity tag code
– jitesh mohite
Nov 8 at 5:13
@jiteshmohite if you are referring to know the launch mode of the Activity_T it is android:launchMode="singleTask" and for Mainactivity there is no launchmode set
– LoveDroid
Nov 8 at 5:23
try this, intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP| Intent.FLAG_ACTIVITY_SINGLE_TOP);
– jitesh mohite
Nov 8 at 5:23
@jiteshmohite thank you, I have just tried it but didn't solve the issue.
– LoveDroid
Nov 8 at 5:28
Remove singleTask from menifest and see.
– jitesh mohite
Nov 8 at 5:30
|
show 4 more comments
1
Can you post the manifest? or some activity tag code
– jitesh mohite
Nov 8 at 5:13
@jiteshmohite if you are referring to know the launch mode of the Activity_T it is android:launchMode="singleTask" and for Mainactivity there is no launchmode set
– LoveDroid
Nov 8 at 5:23
try this, intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP| Intent.FLAG_ACTIVITY_SINGLE_TOP);
– jitesh mohite
Nov 8 at 5:23
@jiteshmohite thank you, I have just tried it but didn't solve the issue.
– LoveDroid
Nov 8 at 5:28
Remove singleTask from menifest and see.
– jitesh mohite
Nov 8 at 5:30
1
1
Can you post the manifest? or some activity tag code
– jitesh mohite
Nov 8 at 5:13
Can you post the manifest? or some activity tag code
– jitesh mohite
Nov 8 at 5:13
@jiteshmohite if you are referring to know the launch mode of the Activity_T it is android:launchMode="singleTask" and for Mainactivity there is no launchmode set
– LoveDroid
Nov 8 at 5:23
@jiteshmohite if you are referring to know the launch mode of the Activity_T it is android:launchMode="singleTask" and for Mainactivity there is no launchmode set
– LoveDroid
Nov 8 at 5:23
try this, intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP| Intent.FLAG_ACTIVITY_SINGLE_TOP);
– jitesh mohite
Nov 8 at 5:23
try this, intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP| Intent.FLAG_ACTIVITY_SINGLE_TOP);
– jitesh mohite
Nov 8 at 5:23
@jiteshmohite thank you, I have just tried it but didn't solve the issue.
– LoveDroid
Nov 8 at 5:28
@jiteshmohite thank you, I have just tried it but didn't solve the issue.
– LoveDroid
Nov 8 at 5:28
Remove singleTask from menifest and see.
– jitesh mohite
Nov 8 at 5:30
Remove singleTask from menifest and see.
– jitesh mohite
Nov 8 at 5:30
|
show 4 more comments
2 Answers
2
active
oldest
votes
up vote
0
down vote
I send notification from receiver onReceive method. When click on notification,I open an activity,even the app was killed. I used like that
Intent notificationIntent = new Intent(context, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context, "")
.setSmallIcon(R.drawable.my_ic)
.setContentTitle(title)
.setContentText(msg)
.setContentIntent(contentIntent);
add a comment |
up vote
0
down vote
Try below code...Change YOUR_ACTIVITY.CLASS with your activity name...
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Intent intent=new Intent(this,YOUR_ACTIVITY.CLASS);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent=PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_ONE_SHOT);//new PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder notificationBuilder= new NotificationCompat.Builder(this);
notificationBuilder.setContentTitle("FCM NOTIFICATION");
notificationBuilder.setContentText(Objects.requireNonNull(remoteMessage.getNotification()).getBody());
notificationBuilder.setAutoCancel(true);
notificationBuilder.setSmallIcon(R.mipmap.ic_launcher);
notificationBuilder.setContentIntent(pendingIntent);
NotificationManager notificationManager =(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
assert notificationManager != null;
notificationManager.notify(0,notificationBuilder.build());
}
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
I send notification from receiver onReceive method. When click on notification,I open an activity,even the app was killed. I used like that
Intent notificationIntent = new Intent(context, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context, "")
.setSmallIcon(R.drawable.my_ic)
.setContentTitle(title)
.setContentText(msg)
.setContentIntent(contentIntent);
add a comment |
up vote
0
down vote
I send notification from receiver onReceive method. When click on notification,I open an activity,even the app was killed. I used like that
Intent notificationIntent = new Intent(context, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context, "")
.setSmallIcon(R.drawable.my_ic)
.setContentTitle(title)
.setContentText(msg)
.setContentIntent(contentIntent);
add a comment |
up vote
0
down vote
up vote
0
down vote
I send notification from receiver onReceive method. When click on notification,I open an activity,even the app was killed. I used like that
Intent notificationIntent = new Intent(context, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context, "")
.setSmallIcon(R.drawable.my_ic)
.setContentTitle(title)
.setContentText(msg)
.setContentIntent(contentIntent);
I send notification from receiver onReceive method. When click on notification,I open an activity,even the app was killed. I used like that
Intent notificationIntent = new Intent(context, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context, "")
.setSmallIcon(R.drawable.my_ic)
.setContentTitle(title)
.setContentText(msg)
.setContentIntent(contentIntent);
answered Nov 8 at 5:32
enesgonez
666
666
add a comment |
add a comment |
up vote
0
down vote
Try below code...Change YOUR_ACTIVITY.CLASS with your activity name...
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Intent intent=new Intent(this,YOUR_ACTIVITY.CLASS);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent=PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_ONE_SHOT);//new PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder notificationBuilder= new NotificationCompat.Builder(this);
notificationBuilder.setContentTitle("FCM NOTIFICATION");
notificationBuilder.setContentText(Objects.requireNonNull(remoteMessage.getNotification()).getBody());
notificationBuilder.setAutoCancel(true);
notificationBuilder.setSmallIcon(R.mipmap.ic_launcher);
notificationBuilder.setContentIntent(pendingIntent);
NotificationManager notificationManager =(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
assert notificationManager != null;
notificationManager.notify(0,notificationBuilder.build());
}
add a comment |
up vote
0
down vote
Try below code...Change YOUR_ACTIVITY.CLASS with your activity name...
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Intent intent=new Intent(this,YOUR_ACTIVITY.CLASS);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent=PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_ONE_SHOT);//new PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder notificationBuilder= new NotificationCompat.Builder(this);
notificationBuilder.setContentTitle("FCM NOTIFICATION");
notificationBuilder.setContentText(Objects.requireNonNull(remoteMessage.getNotification()).getBody());
notificationBuilder.setAutoCancel(true);
notificationBuilder.setSmallIcon(R.mipmap.ic_launcher);
notificationBuilder.setContentIntent(pendingIntent);
NotificationManager notificationManager =(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
assert notificationManager != null;
notificationManager.notify(0,notificationBuilder.build());
}
add a comment |
up vote
0
down vote
up vote
0
down vote
Try below code...Change YOUR_ACTIVITY.CLASS with your activity name...
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Intent intent=new Intent(this,YOUR_ACTIVITY.CLASS);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent=PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_ONE_SHOT);//new PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder notificationBuilder= new NotificationCompat.Builder(this);
notificationBuilder.setContentTitle("FCM NOTIFICATION");
notificationBuilder.setContentText(Objects.requireNonNull(remoteMessage.getNotification()).getBody());
notificationBuilder.setAutoCancel(true);
notificationBuilder.setSmallIcon(R.mipmap.ic_launcher);
notificationBuilder.setContentIntent(pendingIntent);
NotificationManager notificationManager =(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
assert notificationManager != null;
notificationManager.notify(0,notificationBuilder.build());
}
Try below code...Change YOUR_ACTIVITY.CLASS with your activity name...
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Intent intent=new Intent(this,YOUR_ACTIVITY.CLASS);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent=PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_ONE_SHOT);//new PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder notificationBuilder= new NotificationCompat.Builder(this);
notificationBuilder.setContentTitle("FCM NOTIFICATION");
notificationBuilder.setContentText(Objects.requireNonNull(remoteMessage.getNotification()).getBody());
notificationBuilder.setAutoCancel(true);
notificationBuilder.setSmallIcon(R.mipmap.ic_launcher);
notificationBuilder.setContentIntent(pendingIntent);
NotificationManager notificationManager =(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
assert notificationManager != null;
notificationManager.notify(0,notificationBuilder.build());
}
answered Nov 8 at 5:49
VikaS
3110
3110
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%2f53201593%2fopen-activity-on-notification-click-intent-flag-issue%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
1
Can you post the manifest? or some activity tag code
– jitesh mohite
Nov 8 at 5:13
@jiteshmohite if you are referring to know the launch mode of the Activity_T it is android:launchMode="singleTask" and for Mainactivity there is no launchmode set
– LoveDroid
Nov 8 at 5:23
try this, intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP| Intent.FLAG_ACTIVITY_SINGLE_TOP);
– jitesh mohite
Nov 8 at 5:23
@jiteshmohite thank you, I have just tried it but didn't solve the issue.
– LoveDroid
Nov 8 at 5:28
Remove singleTask from menifest and see.
– jitesh mohite
Nov 8 at 5:30