android - Get Started Notification with PendingIntent

Android Notification Example


MainActivity.java

Intent intent = new Intent(this, twoActivity.class);
intent.putExtra("msg", "hello iam ak1");

TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(twoActivity.class);
stackBuilder.addNextIntent(intent);

PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

Notification notification = new NotificationCompat.Builder(this) // this is context
                .setSmallIcon(R.mipmap.ic_launcher)
                .setContentTitle("test")
                .setContentText("test")
                .setAutoCancel(true)
                .setContentIntent(pendingIntent)
                .build();

NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(2, notification);



twoActivity.java

Bundle bundle = getIntent().getExtras();
String message = bundle.getString("msg");
Toast.makeText(twoActivity.this, " Message : "+message, Toast.LENGTH_LONG).show();



ไม่มีความคิดเห็น:

แสดงความคิดเห็น