Refine search
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context) .setColor(ContextCompat.getColor(context,R.color.colorPrimary)) .setSmallIcon(smallArtResourceId) .setLargeIcon(largeIcon) .setContentTitle(notificationTitle) Intent detailIntentForToday = new Intent(context, DetailActivity.class); detailIntentForToday.setData(todaysWeatherUri); TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context); taskStackBuilder.addNextIntentWithParentStack(detailIntentForToday); PendingIntent resultPendingIntent = taskStackBuilder .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); notificationBuilder.setContentIntent(resultPendingIntent); notificationManager.notify(WEATHER_NOTIFICATION_ID, notificationBuilder.build());
RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.widget); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder( this).setSmallIcon(R.drawable.ic_launcher).setContent( remoteViews); // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(this, test.class); // The stack builder object will contain an artificial back stack for // the // started Activity. // This ensures that navigating backward from the Activity leads out of // your application to the Home screen. TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(test.class); // Adds the Intent that starts the Activity to the top of the stack stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); remoteViews.setOnClickPendingIntent(R.id.button1, resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); // mId allows you to update the notification later on. mNotificationManager.notify(100, mBuilder.build());
@Override protected void onStart() { super.onStart(); TaskStackBuilder.create(this) .addNextIntentWithParentStack(new Intent(this, MainActivity.class)) .addNextIntent(new Intent(this, IntroActivity.class)) .startActivities(); } }
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(FieldAgent.class); stackBuilder.addNextIntent(intent); PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
private TaskStackBuilder buildAccountsBackStack() { TaskStackBuilder stack = TaskStackBuilder.create(context); if (!skipAccountsInBackStack()) { Intent intent = new Intent(context, Accounts.class); intent.putExtra(Accounts.EXTRA_STARTUP, false); stack.addNextIntent(intent); } return stack; }
Context context; Intent broadcastIntent = new Intent(); this.context = context; broadcastIntent.addCategory(GeofenceUtils.CATEGORY_LOCATION_SERVICES); .setAction(GeofenceUtils.ACTION_GEOFENCE_ERROR) .putExtra(GeofenceUtils.EXTRA_GEOFENCE_STATUS, errorMessage); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(notificationIntent); .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); builder.setSmallIcon(R.drawable.ic_notification) .setContentTitle(transitionType + ": " + locationName) .setContentText( mNotificationManager.notify(0, builder.build());
/** Starts the Settings Activity if connection settings are missing * * @return true if setup was started */ private boolean startSetupIfNeeded(){ Preferences preferences = new Preferences(getApplicationContext()); if (TextUtils.isEmpty(preferences.getString(R.string.pref_key_host, null)) || preferences.getInt(R.string.pref_key_port, -1) == -1){ Intent settingsIntent = new Intent(this, SettingsActivity.class); settingsIntent.putExtra(SettingsActivity.EXTRA_SHOW_TOAST_KEY, SettingsActivity.EXTRA_SHOW_TOAST_SETUP_REQUIRED_FOR_QUICK_TILE); settingsIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // Use TaskStackBuilder to make sure the MainActivity opens when the SettingsActivity is closed TaskStackBuilder.create(this) .addNextIntentWithParentStack(settingsIntent) .startActivities(); Intent closeIntent = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); sendBroadcast(closeIntent); return true; } return false; } }
manager.cancel(ERROR_NOTIFICATION_ID); notificationChannel.enableLights(false); notificationChannel.enableVibration(false); manager.createNotificationChannel(notificationChannel); Intent appIntent = new Intent(ctx, MainActivity.class); appIntent.setAction(Intent.ACTION_MAIN); appIntent.addCategory(Intent.CATEGORY_LAUNCHER); appIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); TaskStackBuilder stackBuilder = TaskStackBuilder.create(ctx) .addParentStack(MainActivity.class) .addNextIntent(new Intent(ctx, MainActivity.class)); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(ctx, NOTIFICATION_CHANNEL_ID); notificationBuilder.setContentIntent(notifyPendingIntent); Notification notification = notificationBuilder.setOngoing(false) .setCategory(Notification.CATEGORY_ERROR) .setVisibility(Notification.VISIBILITY_SECRET) .build(); manager.notify(ERROR_NOTIFICATION_ID, notification);
PendingIntent contentIntent ; Intent intent = new Intent(this,TestActivity.class); intent.putExtra("extra","Test"); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(ArticleDetailedActivity.class); contentIntent = stackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT);
private PendingIntent buildPendingIntent(String id, String itemUri) { Intent detailsIntent = new Intent(this, MainActivity.class); detailsIntent.setData(Uri.parse(itemUri)); // Ensure a unique PendingIntents, otherwise all recommendations end up with the same PendingIntent detailsIntent.setAction(id); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(detailsIntent); PendingIntent intent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); return intent; } }
builder = new NotificationCompat.Builder(context,CHANNEL_ID); Intent appIntent = new Intent(context, MainActivity.class); channel.enableLights(false); channel.enableVibration(false); notificationManager.createNotificationChannel(channel); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(appIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(resultPendingIntent); Notification notification = builder.setSmallIcon(R.drawable.ic_apply_notification) .setAutoCancel(false) .setContentTitle(context.getString(R.string.applying_rules)) builder.setProgress(0, 0, true); notificationManager.notify(NOTIFICATION_ID, notification);
Intent intent = new Intent(this, Receive.class); intent.setAction("action"); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.ic_launcher) .setContent(remoteViews); Intent resultIntent = new Intent(this, songFocus.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(songFocus.class); stackBuilder.addNextIntent(resultIntent); PendingIntent pIntent = PendingIntent.getBroadcast(this,0,intent,PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(pIntent); // setting the PendingIntent here startForeground(256781,mBuilder.build());
Intent activityInBackstack = new Intent(this, ActivityA.class); Intent activityToBeLaunched = new Intent(this, ActivityB.class); TaskStackBuilder builder = TaskStackBuilder.create(this); builder.addNextIntent(activityInBackstack); builder.addNextIntent(activityToBeLaunched); builder.startActivities();
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: // This is called when the Home (Up) button is pressed in the action bar. // Create a simple intent that starts the hierarchical parent activity and // use NavUtils in the Support Package to ensure proper handling of Up. Intent upIntent = new Intent(this, MainActivity.class); if (NavUtils.shouldUpRecreateTask(this, upIntent)) { // This activity is not part of the application's task, so create a new task // with a synthesized back stack. TaskStackBuilder.from(this) // If there are ancestor activities, they should be added here. .addNextIntent(upIntent) .startActivities(); finish(); } else { // This activity is part of the application's task, so simply // navigate up to the hierarchical parent activity. NavUtils.navigateUpTo(this, upIntent); } return true; } return super.onOptionsItemSelected(item); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle b = getIntent().getExtras(); fromNotification = b.getInt("fromNotification") == 1; setContentView(R.layout.threadlist); } @Override public boolean onHomeButtonPressed() { if(fromNotification) { // This activity is not part of the application's task, so create a new task // with a synthesized back stack. TaskStackBuilder tsb = TaskStackBuilder.from(this) .addNextIntent(new Intent(this, COPAme.class)); tsb.startActivities(); } // Otherwise, This activity is part of the application's task, so simply // navigate up to the hierarchical parent activity. finish(); return true; }
JSONObject pushData = new JSONObject(intent.getStringExtra("com.parse.Data")); uriString = pushData.optString("uri"); } catch (JSONException e) { activityIntent = new Intent(context, MainActivity.class); activityIntent.putExtras(intent.getExtras()); if (Build.VERSION.SDK_INT >= 16) { TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(cls); stackBuilder.addNextIntent(activityIntent); stackBuilder.startActivities(); } else { activityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
TaskStackBuilder stack = TaskStackBuilder.create(context); Intent classAct = new Intent(context, ClassActivity.class); // This will clear any opened activities. Use if necessary classAct.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); Intent studentAct = new Intent(context, StudentActivity.class); studentAct.putExtra("exam_id", 123); stack.addNextIntent(home); stack.addNextIntent(studentAct); stack.addNextIntent(new Intent(context, StudentExamActivity.class)); stack.startActivities();
public static void navigateUp(Activity activity, Bundle extras) { Intent upIntent = NavUtils.getParentActivityIntent(activity); if (upIntent != null) { if (extras != null) { upIntent.putExtras(extras); } if (NavUtils.shouldUpRecreateTask(activity, upIntent)) { // This activity is NOT part of this app's task, so create a new task // when navigating up, with a synthesized back stack. TaskStackBuilder.create(activity) // Add all of this activity's parents to the back stack. .addNextIntentWithParentStack(upIntent) // Navigate up to the closest parent. .startActivities(); } else { // This activity is part of this app's task, so simply // navigate up to the logical parent activity. // According to http://stackoverflow.com/a/14792752/2420519 //NavUtils.navigateUpTo(activity, upIntent); upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); activity.startActivity(upIntent); } } activity.finish(); }
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { // Respond to the action bar's Up/Home button case android.R.id.home: Intent upIntent = NavUtils.getParentActivityIntent(this); upIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); if (NavUtils.shouldUpRecreateTask(this, upIntent)) { // This activity is NOT part of this app's task, so create a new task // when navigating up, with a synthesized back stack. TaskStackBuilder.create(this) // Add all of this activity's parents to the back stack .addNextIntentWithParentStack(upIntent) // Navigate up to the closest parent .startActivities(); } else { // This activity is part of this app's task, so simply // navigate up to the logical parent activity. NavUtils.navigateUpTo(this, upIntent); } return true; } return super.onOptionsItemSelected(item); }
public static PendingIntent addBackStack(final Context context, final Intent intent) { TaskStackBuilder stackBuilder = TaskStackBuilder.create (context.getApplicationContext ()); stackBuilder.addNextIntentWithParentStack (intent); intent.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK); return stackBuilder.getPendingIntent (0,PendingIntent.FLAG_UPDATE_CURRENT); }