Example usage for android.app TaskStackBuilder create

List of usage examples for android.app TaskStackBuilder create

Introduction

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

Prototype

public static TaskStackBuilder create(Context context) 

Source Link

Document

Return a new TaskStackBuilder for launching a fresh task stack consisting of a series of activities.

Usage

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.example.android.xyztouristattractions.ui.DetailFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        // Some small additions to handle "up" navigation correctly
        Intent upIntent = NavUtils.getParentActivityIntent(getActivity());
        upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);

        // Check if up activity needs to be created (usually when
        // detail screen is opened from a notification or from the
        // Wearable app
        if (NavUtils.shouldUpRecreateTask(getActivity(), upIntent) || getActivity().isTaskRoot()) {

            // Synthesize parent stack
            TaskStackBuilder.create(getActivity()).addNextIntentWithParentStack(upIntent).startActivities();
        }/*from   ww w.ja  v a  2 s  .  com*/

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            // On Lollipop+ we finish so to run the nice animation
            getActivity().finishAfterTransition();
            return true;
        }

        // Otherwise let the system handle navigating "up"
        return false;
    case R.id.map:
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(
                Uri.parse(Constants.MAPS_INTENT_URI + Uri.encode(mAttraction.name + ", " + mAttraction.city)));
        startActivity(intent);
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.android.example.leanback.fastlane.RecommendationsService.java

private PendingIntent buildPendingIntent(Video video) {
    Intent detailsIntent = new Intent(this, PlayerActivity.class);
    detailsIntent.putExtra(Video.INTENT_EXTRA_VIDEO, video);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(VideoDetailsActivity.class);
    stackBuilder.addNextIntent(detailsIntent);
    // Ensure a unique PendingIntents, otherwise all recommendations end up with the same
    // PendingIntent
    detailsIntent.setAction(Long.toString(video.getId()));

    PendingIntent intent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    return intent;
}

From source file:com.asburymotors.android.disneysocal.ui.DetailFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        // Some small additions to handle "up" navigation correctly
        Intent upIntent = NavUtils.getParentActivityIntent(getActivity());
        upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);

        // Check if up activity needs to be created (usually when
        // detail screen is opened from a notification or from the
        // Wearable app
        if (NavUtils.shouldUpRecreateTask(getActivity(), upIntent) || getActivity().isTaskRoot()) {

            // Synthesize parent stack
            TaskStackBuilder.create(getActivity()).addNextIntentWithParentStack(upIntent).startActivities();
        }//from  w  w w  .j  a  v  a  2  s  . c  o m

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            // On Lollipop+ we finish so to run the nice animation
            getActivity().finishAfterTransition();
            return true;
        }

        // Otherwise let the system handle navigating "up"
        return false;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.kyleszombathy.sms_scheduler.Home.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.d(TAG, "Activity View Created");

    // Setting up transitions
    getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
    getWindow().setExitTransition(new Fade());

    setContentView(R.layout.activity_home);

    Toolbar toolbar = (Toolbar) findViewById(R.id.SMSScheduler_Toolbar);
    setActionBar(toolbar);/*from   w  ww .j a v a2s  . c o m*/

    populateDatasets();
    setUpRecyclerView();

    LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver,
            new IntentFilter("custom-event-name"));

    parentView = findViewById(R.id.Home_coordLayout);

    prefs = getSharedPreferences("com.kyleszombathy.sms_scheduler", MODE_PRIVATE);

    // Floating action button start activity
    findViewById(R.id.Home_fab).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // Random alarm number
            int alarmNumber = getRandomInt(MIN_INT, MAX_INT);

            Intent intent = new Intent(new Intent(Home.this, AddMessage.class));
            Bundle extras = new Bundle();
            extras.putInt(ALARM_EXTRA, alarmNumber);
            extras.putBoolean(EDIT_MESSAGE_EXTRA, false);
            intent.putExtras(extras);

            TaskStackBuilder stackBuilder = TaskStackBuilder.create(Home.this);
            stackBuilder.addParentStack(AddMessage.class);
            stackBuilder.addNextIntent(intent);
            PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
                    PendingIntent.FLAG_UPDATE_CURRENT);

            Log.d(TAG, "Starting Activity AddMessage");

            startActivityForResult(intent, NEW_MESSAGE,
                    ActivityOptions.makeSceneTransitionAnimation(Home.this).toBundle());
        }
    });
}

From source file:com.fairphone.updater.UpdaterService.java

private void setNotification() {

    Context context = getApplicationContext();

    NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.fairphone_updater_tray_icon_small)
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.fairphone_updater_tray_icon))
            .setContentTitle(context.getResources().getString(R.string.app_name))
            .setContentText(getResources().getString(R.string.fairphoneUpdateMessage));

    Intent resultIntent = new Intent(context, FairphoneUpdater.class);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);

    stackBuilder.addParentStack(FairphoneUpdater.class);

    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    builder.setContentIntent(resultPendingIntent);

    Notification notificationWhileRunnig = builder.build();

    // Add notification
    manager.notify(0, notificationWhileRunnig);

}

From source file:net.yoching.android.MainActivity.java

/**
 * Called when the activity is first created.
 *//*www. ja v  a  2 s . com*/
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    throwButton = (Button) findViewById(R.id.throw_button);
    throwButton.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/Exo-ExtraBold.otf"));
    initCoinToss();
    addDrawerItems();

    WrexagramListAdapter adapter = new WrexagramListAdapter(MainActivity.this, wrexagramTitles,
            wrexagramSubTitles, wrexagramImageIds);

    mDrawerList = (ListView) findViewById(R.id.navList);

    mDrawerList.setAdapter(adapter);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mActivityTitle = getTitle().toString();

    setupDrawer();

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    //getSupportActionBar().setLogo(R.drawable.ic_launcher);
    getSupportActionBar().setHomeButtonEnabled(true);

    TextView toolbarTitle = (TextView) findViewById(R.id.toolbar_title);
    toolbarTitle.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/Exo-ExtraBold.otf"));

    int width = getResources().getDisplayMetrics().widthPixels;
    DrawerLayout.LayoutParams params = (android.support.v4.widget.DrawerLayout.LayoutParams) mDrawerList
            .getLayoutParams();
    params.width = width;
    mDrawerList.setLayoutParams(params);

    mDrawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            //Toast.makeText(MainActivity.this, position+" - clicked", Toast.LENGTH_SHORT).show();
            mDrawerLayout.closeDrawers();
            Intent intent = new Intent(MainActivity.this, ViewWrexagramActivity.class);
            //intent.putExtra("string",Yourlist.get(pos).sms);
            intent.putExtra("wrexagram", position + 1 + "");

            PendingIntent pendingIntent = TaskStackBuilder.create(MainActivity.this)
                    // add all of DetailsActivity's parents to the stack,
                    // followed by DetailsActivity itself
                    .addNextIntentWithParentStack(intent)
                    .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

            NotificationCompat.Builder builder = new NotificationCompat.Builder(MainActivity.this);
            builder.setContentIntent(pendingIntent);

            startActivity(intent);
            finish();
        }
    });
}

From source file:com.i2r.xue.rate_this_place.visitedplace.GeofenceTransitionsIntentService.java

/**
 * Posts a notification in the notification bar when a transition is detected.
 * If the user clicks the notification, control goes to the MainActivity.
 *//*  w w  w .j  a  va2 s  .c o m*/
private void sendNotification(String notificationDetails) {
    // Create an explicit content Intent that starts the main Activity.
    Intent notificationIntent = new Intent(getApplicationContext(), VisitedPlacesActivity.class);

    // Construct a task stack.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);

    // Add the main Activity to the task stack as the parent.
    stackBuilder.addParentStack(MainActivity.class);

    // Push the content Intent onto the stack.
    stackBuilder.addNextIntent(notificationIntent);

    // Get a PendingIntent containing the entire back stack.
    PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0,
            PendingIntent.FLAG_UPDATE_CURRENT);

    // Get a notification builder that's compatible with platform versions >= 4
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);

    // Define the notification settings.
    builder.setSmallIcon(com.i2r.xue.rate_this_place.R.mipmap.ic_launcher)
            // In a real app, you may want to use a library like Volley
            // to decode the Bitmap.
            .setLargeIcon(BitmapFactory.decodeResource(getResources(),
                    com.i2r.xue.rate_this_place.R.mipmap.ic_launcher))
            .setColor(Color.RED).setContentTitle(notificationDetails)
            .setContentText(
                    getString(com.i2r.xue.rate_this_place.R.string.geofence_transition_notification_text))
            .setContentIntent(notificationPendingIntent);

    // Dismiss notification once the user touches it.
    builder.setAutoCancel(true);

    // Get an instance of the Notification manager
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    // Issue the notification
    mNotificationManager.notify(0, builder.build());
}

From source file:com.matze5800.paupdater.Functions.java

public static void Notify(Context context, String text) {
    Log.i("notify", text);
    Notification.Builder nBuilder;
    nBuilder = new Notification.Builder(context);
    Intent resultIntent = new Intent(context, Cancel.class);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addParentStack(Cancel.class);
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    nBuilder.setContentIntent(resultPendingIntent);
    nBuilder.setSmallIcon(R.drawable.ic_launcher);
    nBuilder.setContentTitle("PA Updater");
    nBuilder.setContentText(text);//from   w w  w . j  a va2s  . co m
    nBuilder.setAutoCancel(false);
    nBuilder.setOngoing(true);
    NotificationManager mNotificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(1, nBuilder.build());
}

From source file:com.i2r.alan.rate_this_place.visitedplace.GeofenceTransitionsIntentService.java

/**
 * Posts a notification in the notification bar when a transition is detected.
 * If the user clicks the notification, control goes to the MainActivity.
 *//* w w  w .  j av a  2  s  .c  om*/
private void sendNotification(String notificationDetails) {
    // Create an explicit content Intent that starts the main Activity.
    Intent notificationIntent = new Intent(getApplicationContext(), VisitedPlacesActivity.class);

    // Construct a task stack.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);

    // Add the main Activity to the task stack as the parent.
    stackBuilder.addParentStack(MainActivity.class);

    // Push the content Intent onto the stack.
    stackBuilder.addNextIntent(notificationIntent);

    // Get a PendingIntent containing the entire back stack.
    PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0,
            PendingIntent.FLAG_UPDATE_CURRENT);

    // Get a notification builder that's compatible with platform versions >= 4
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);

    // Define the notification settings.
    builder.setSmallIcon(com.i2r.alan.rate_this_place.R.mipmap.ic_launcher)
            // In a real app, you may want to use a library like Volley
            // to decode the Bitmap.
            .setLargeIcon(BitmapFactory.decodeResource(getResources(),
                    com.i2r.alan.rate_this_place.R.mipmap.ic_launcher))
            .setColor(Color.RED).setContentTitle(notificationDetails)
            .setContentText(
                    getString(com.i2r.alan.rate_this_place.R.string.geofence_transition_notification_text))
            .setContentIntent(notificationPendingIntent);

    // Dismiss notification once the user touches it.
    builder.setAutoCancel(true);

    // Get an instance of the Notification manager
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    // Issue the notification
    mNotificationManager.notify(0, builder.build());
}