check this:
private void delayhandler() {
{
long delayMillis = 6000;
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
// user is already login; goto dash board
Intent intent = getIntent();
if (intent != null && intent.hasExtra("xxx")) {
Intent mapActivityIntent = new Intent(getApplicationContext(),
LatestOffersActivity.class);
startActivity(mapActivityIntent);
} else {
Intent mapActivityIntent = new Intent(getApplicationContext(),
HomepageActivity.class);
startActivity(mapActivityIntent);
}
SplashActivity.this.finish();
}
}, delayMillis);
}
}
private void sendNotification(com.fcm.Notification notification) {
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
notificationBuilder
.setSmallIcon(R.mipmap.logo_actionbar)
.setContentTitle(notification.getTitle())
.setContentText(notification.getMessage())
.setSound(defaultSoundUri)
.setAutoCancel(true);
int requestID = (int) System.currentTimeMillis();
notificationBuilder.setContentIntent(getPendingIntent(this, requestID, SplashActivity.class));
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(requestID, notificationBuilder.build());
}
public static PendingIntent getPendingIntent(Context context, int requestID, Class classToLaunch) {
Intent resultIntent = new Intent(context, classToLaunch);
resultIntent.putExtra("xxx", "123");
resultIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addParentStack(classToLaunch);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(requestID, PendingIntent.FLAG_UPDATE_CURRENT);
return resultPendingIntent;
}
You can add in recipient activity onCreate()
the following code:
Bundle extras = getIntent().getExtras();
if (extras == null) {
Log.d("EXTRA, "extra is not received!");
} else {
String data = extras.getString("EXTRA_KEY");
}
If you want to send the intent to foreground activity, you can receive the intent value in onNewIntent()
:
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);//must store the new intent unless getIntent() will return the old one
// recheck the intent
Bundle extras = getIntent().getExtras();
String data = extras.getString("EXTRA_KEY");
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.