Example usage for android.app TaskStackBuilder addParentStack

List of usage examples for android.app TaskStackBuilder addParentStack

Introduction

In this page you can find the example usage for android.app TaskStackBuilder addParentStack.

Prototype

public TaskStackBuilder addParentStack(ComponentName sourceActivityName) 

Source Link

Document

Add the activity parent chain as specified by the android.R.attr#parentActivityName parentActivityName attribute of the activity (or activity-alias) element in the application's manifest to the task stack builder.

Usage

From source file:re.serialout.MainScreen.java

public void buildNotification(Context context) {
    //Feature in progress, not in current version.
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    builder.setContentTitle("There is a new survey for you to complete!");
    builder.setContentText("Please take a second to fill it out.");
    builder.setSmallIcon(R.drawable.logo2);
    builder.setAutoCancel(true);/*from ww w .j  av a  2s  .  c o m*/
    System.out.println("BUILT");
    Intent resultIntent = new Intent(this, MainScreen.class);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addParentStack(MainScreen.class);
    stackBuilder.addNextIntent(resultIntent);

    PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(pendingIntent);
    NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    manager.notify(100, builder.build());
}

From source file:at.aec.solutions.checkmkagent.AgentService.java

@Override
public void onCreate() {
    super.onCreate();
    Log.v(TAG, "onCreate");

    PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
    m_wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakelockTag");
    m_wakeLock.acquire();//from ww w  . ja v  a 2  s  .  c o  m

    //Copy busybox binary to app directory
    if (!PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getBoolean("bbinstalled",
            false)) {
        PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit()
                .putBoolean("bbinstalled", true).commit();

        // There is also String[] Build.SUPPORTED_ABIS from API 21 on and
        // before String Build.CPU_ABI String Build.CPU_ABI2, maybe i should investigate there
        String arch = System.getProperty("os.arch");
        Log.v(TAG, arch);
        if (arch.equals("armv7l")) {
            copyAsset(getAssets(), "bbb/busybox", getApplicationInfo().dataDir + "/busybox");
        }
        if (arch.equals("i686")) {
            copyAsset(getAssets(), "bbb/busybox-i686", getApplicationInfo().dataDir + "/busybox");
        }

        //         copyAsset(getAssets(), "bbb/busybox-x86_64", getApplicationInfo().dataDir+"/busybox-x86_64");
        changeBusyboxPermission();
    }

    socketServerThread = new Thread(new SocketServerThread());
    socketServerThread.setName("CheckMK-Agent ServerThread");
    socketServerThread.start();

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher).setContentTitle("CheckMK Agent started.")
            .setContentText("Listening on Port " + SERVERPORT + ". Tap to configure.");

    Intent resultIntent = new Intent(this, ConfigureActivity.class);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(ConfigureActivity.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);

    mBuilder.setContentIntent(resultPendingIntent);
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    // mId allows you to update the notification later on.
    Notification notify = mBuilder.build();
    notify.flags |= Notification.FLAG_NO_CLEAR;

    mNotificationManager.notify(mId, notify);
}

From source file:com.ithinkbest.taipeiok.NavigationDrawerActivity.java

private void notifyGooglePlay() {
    int idGooglePlay = 12345;
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher).setContentTitle(getString(R.string.app_name))
            .setContentText(getString(R.string.to_google_play));
    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(this, ToGooglePlayActivity.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(ToGooglePlayActivity.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);
    mBuilder.setContentIntent(resultPendingIntent);
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    // mId allows you to update the notification later on.
    mNotificationManager.notify(idGooglePlay, mBuilder.build());

}

From source file:com.ithinkbest.taipeiok.NavigationDrawerActivity.java

private void notifyAppWebpage() {
    int idGooglePlay = 12346;
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher).setContentTitle(getString(R.string.app_name))
            .setContentText(getString(R.string.to_app_webpage));
    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(this, ToAppWebpageActivity.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(ToAppWebpageActivity.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);
    mBuilder.setContentIntent(resultPendingIntent);
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    // mId allows you to update the notification later on.
    mNotificationManager.notify(idGooglePlay, mBuilder.build());

}

From source file:com.fimo_pitch.main.MainActivity.java

private void makeNotification(Context context, String title, String content) {
    Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.mipmap.ic_launcher).setContentTitle(title).setSound(uri)
            .setPriority(Notification.PRIORITY_HIGH).setContentText(content);
    Intent resultIntent = new Intent(context, MainActivity.class);
    userModel = getUserModel();//from   www. j  a v a2  s  .c  o m
    resultIntent.putExtra(CONSTANT.KEY_USER, userModel);
    resultIntent.putExtra(CONSTANT.FROM_NOTIFICATION, "true");
    TaskStackBuilder stackBuilder = null;
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
        stackBuilder = TaskStackBuilder.create(context);
        stackBuilder.addParentStack(FirstActivity.class);
        stackBuilder.addNextIntent(resultIntent);
        PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
        mBuilder.setContentIntent(resultPendingIntent);
        NotificationManager mNotificationManager = (NotificationManager) getSystemService(
                Context.NOTIFICATION_SERVICE);
        mNotificationManager.notify(10, mBuilder.build());
        //            Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
        //            v.vibrate(ZAQ500);
    } else {
        NotificationManager mNotificationManager = (NotificationManager) getSystemService(
                Context.NOTIFICATION_SERVICE);
        mNotificationManager.notify(10, mBuilder.build());
        //            Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
        //            v.vibrate(500);
    }
}

From source file:br.com.Utilitarios.WorkUpService.java

public void criarNotificacoes(Notificacoes n, String titulo, String texto, String ticker, String tipo,
        String extra) {/*from ww w.j a va  2s.  c om*/

    // Build notification
    NotificationCompat.Builder noti = new NotificationCompat.Builder(this);
    noti.setContentTitle(titulo);
    noti.setContentText(texto);
    noti.setTicker(ticker);
    noti.setSmallIcon(R.drawable.ic_launcher);
    Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    noti.setSound(alarmSound);

    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    Intent resultIntent = null;
    if (tipo.equals("novoPersonal")) {
        // Creates an expnovaAvaliacaolicit intent for an Activity in your app
        resultIntent = new Intent(this, AceitarRejeitarAmigo.class);
        resultIntent.putExtra("usuario", n.getOrigemNotificacao());
        resultIntent.putExtra("tipo", "aluno");
    }

    if (tipo.equals("novoAluno")) {

        resultIntent = new Intent(this, AceitarRejeitarAmigo.class);
        resultIntent.putExtra("usuario", n.getOrigemNotificacao());
        resultIntent.putExtra("tipo", "personal");

    }

    if (tipo.equals("novaAula")) {
        // Creates an explicit intent for an Activity in your app
        resultIntent = new Intent(this, ConfirmarAula.class);
        resultIntent.putExtra("codAula", extra);
    }

    //This ensures that navigating backward from the Activity leads out of the app to Home page
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);

    if (tipo.equals("novoPersonal") || tipo.equals("novoAluno")) {
        // Adds the back stack for the Intent
        stackBuilder.addParentStack(AceitarRejeitarAmigo.class);

        // Adds the Intent that starts the Activity to the top of the stack
        stackBuilder.addNextIntent(resultIntent);
        PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_ONE_SHOT //can only be used once
        );
        // start the activity when the user clicks the notification text
        noti.setContentIntent(resultPendingIntent);
    }

    // pass the Notification object to the system
    notificationManager.notify(0, noti.build());

    n.visualizarNotificacao(n.getCodNotificacao());

    //----------------------------------------------------------------------------------
}

From source file:ua.mkh.weather.MainActivity.java

private void create_notif() {
    // TODO Auto-generated method stub
    // Prepare intent which is triggered if the
    // notification is selected
    String tittle = textView3.getText().toString();
    String subject = textView3.getText().toString();
    String body = "";
    /*// w  w w .  j  ava  2  s. c o m
    NotificationManager notif=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notify=new Notification((Integer)img1.getTag(),tittle,System.currentTimeMillis());
    PendingIntent pending= PendingIntent.getActivity(getApplicationContext(), 0, new Intent(), 0);
            
    notify.setLatestEventInfo(getApplicationContext(),subject,body,pending);
    notif.notify(0, notify);
            
            
    final NotificationManager mgr=
    (NotificationManager)this.getSystemService(Context.NOTIFICATION_SERVICE);
        Notification note=new Notification((Integer)img1.getTag(),
      "",
                                                System.currentTimeMillis());
                 
        // This pending intent will open after notification click
        PendingIntent i=PendingIntent.getActivity(this, 0,
                                        new Intent(),
                                        0);
                 
        note.setLatestEventInfo(this, tittle,
      "", i);
                 
        //After uncomment this line you will see number of notification arrived
        //note.number=2;
        mgr.notify(1, note);
                
                
        PendingIntent pi = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0);
        Resources r = getResources();
        Notification notification = new NotificationCompat.Builder(this)
        .setTicker("Tiket")
        .setSmallIcon(android.R.drawable.ic_menu_report_image)
        .setContentTitle("Title")
        .setContentText("Context Text")
        .setContentIntent(pi)
        .setAutoCancel(true)
        .build();
            
        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        notificationManager.notify(0, notification);
    */

    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, MainActivity.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(MainActivity.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);
    remoteViews.setTextViewText(R.id.textView1, nnn);
    remoteViews.setTextColor(R.id.textView1, getResources().getColor(R.color.white));
    remoteViews.setImageViewResource(R.id.imageView1, (Integer) img1.getTag());
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    // mId allows you to update the notification later on.  
    mNotificationManager.notify(100, mBuilder.build());

}

From source file:org.tigase.messenger.phone.pro.service.XMPPService.java

private void processAuthenticationError(final Jaxmpp jaxmpp) {
    Log.e(TAG, "Invalid credentials of account " + jaxmpp.getSessionObject().getUserBareJid());
    jaxmpp.getSessionObject().setUserProperty("CC:DISABLED", true);

    String title = getString(R.string.notification_credentials_error_title,
            jaxmpp.getSessionObject().getUserBareJid().toString());
    String text = getString(R.string.notification_certificate_error_text);

    Intent resultIntent = new Intent(this, LoginActivity.class);
    resultIntent.putExtra("account_name", jaxmpp.getSessionObject().getUserBareJid().toString());

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(ChatActivity.class);
    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent editServerSettingsPendingIntent = stackBuilder.getPendingIntent(0,
            PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            // .setSmallIcon(R.drawable.ic_messenger_icon)
            .setSmallIcon(android.R.drawable.stat_notify_error).setWhen(System.currentTimeMillis())
            .setAutoCancel(true).setTicker(title).setContentTitle(title).setContentText(text)
            .setContentIntent(editServerSettingsPendingIntent)
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC);

    builder.setLights(0xffff0000, 100, 100);

    // getNotificationManager().notify(notificationId, builder.build());

    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(("error:" + jaxmpp.getSessionObject().getUserBareJid().toString()).hashCode(),
            builder.build());/*from  w w w  . ja  v a  2s.  com*/
}

From source file:org.tigase.messenger.phone.pro.service.XMPPService.java

private void processCertificateError(final Jaxmpp jaxmpp,
        final SecureTrustManagerFactory.DataCertificateException cause) {
    Log.e(TAG, "Invalid certificate of account " + jaxmpp.getSessionObject().getUserBareJid() + ": "
            + cause.getMessage());// w  w w  .  j a  v  a 2 s  .  c  o m
    jaxmpp.getSessionObject().setUserProperty("CC:DISABLED", true);

    String title = getString(R.string.notification_certificate_error_title,
            jaxmpp.getSessionObject().getUserBareJid().toString());
    String text = getString(R.string.notification_certificate_error_text);

    Intent resultIntent = new Intent(this, LoginActivity.class);
    resultIntent.putExtra("account_name", jaxmpp.getSessionObject().getUserBareJid().toString());

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(ChatActivity.class);
    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent editServerSettingsPendingIntent = stackBuilder.getPendingIntent(0,
            PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            // .setSmallIcon(R.drawable.ic_messenger_icon)
            .setSmallIcon(android.R.drawable.stat_notify_error).setWhen(System.currentTimeMillis())
            .setAutoCancel(true).setTicker(title).setContentTitle(title).setContentText(text)
            .setContentIntent(editServerSettingsPendingIntent)
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC);

    builder.setLights(0xffff0000, 100, 100);

    // getNotificationManager().notify(notificationId, builder.build());

    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(("error:" + jaxmpp.getSessionObject().getUserBareJid().toString()).hashCode(),
            builder.build());
}

From source file:org.tigase.messenger.phone.pro.service.XMPPService.java

private void processSubscriptionRequest(final SessionObject sessionObject, final Presence stanza,
        final BareJID jid) {
    Log.e(TAG, "Subscription request from  " + jid);

    retrieveVCard(sessionObject, jid);//from  w w w  .  j a v a 2  s.c  om

    String title = getString(R.string.notification_subscription_request_title, jid.toString());
    String text = getString(R.string.notification_subscription_request_text);

    Intent resultIntent = new Intent(this, SubscriptionRequestActivity.class);
    resultIntent.putExtra("account_name", sessionObject.getUserBareJid().toString());
    resultIntent.putExtra("jid", jid.toString());

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(ChatActivity.class);
    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent editServerSettingsPendingIntent = stackBuilder.getPendingIntent(0,
            PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            // .setSmallIcon(R.drawable.ic_messenger_icon)
            .setSmallIcon(R.drawable.ic_messenger_icon).setWhen(System.currentTimeMillis()).setAutoCancel(true)
            .setTicker(title).setContentTitle(title).setContentText(text)
            .setContentIntent(editServerSettingsPendingIntent)
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC);

    builder.setLights(0xff0000ff, 100, 100);

    // getNotificationManager().notify(notificationId, builder.build());

    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(("request:" + sessionObject.getUserBareJid().toString() + ":" + jid).hashCode(),
            builder.build());
}