Example usage for android.content Intent FLAG_ACTIVITY_SINGLE_TOP

List of usage examples for android.content Intent FLAG_ACTIVITY_SINGLE_TOP

Introduction

In this page you can find the example usage for android.content Intent FLAG_ACTIVITY_SINGLE_TOP.

Prototype

int FLAG_ACTIVITY_SINGLE_TOP

To view the source code for android.content Intent FLAG_ACTIVITY_SINGLE_TOP.

Click Source Link

Document

If set, the activity will not be launched if it is already running at the top of the history stack.

Usage

From source file:com.pi.android.brainbeats.ui.PlaybackControlsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View rootView = inflater.inflate(R.layout.fragment_playback_controls, container, false);

    mPlayPause = (ImageButton) rootView.findViewById(R.id.play_pause);
    mPlayPause.setEnabled(true);/*w  w  w.  j a  v a  2s . c om*/
    mPlayPause.setOnClickListener(mButtonListener);

    mTitle = (TextView) rootView.findViewById(R.id.title);
    mSubtitle = (TextView) rootView.findViewById(R.id.artist);
    mExtraInfo = (TextView) rootView.findViewById(R.id.extra_info);
    mAlbumArt = (ImageView) rootView.findViewById(R.id.album_art);
    tagger = new Tagger(getActivity());
    rootView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(getActivity(), FullScreenPlayerActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
            MediaControllerCompat controller = ((FragmentActivity) getActivity()).getSupportMediaController();
            MediaMetadataCompat metadata = controller.getMetadata();
            if (metadata != null) {
                intent.putExtra(MusicPlayerActivity.EXTRA_CURRENT_MEDIA_DESCRIPTION, metadata.getDescription());
            }
            startActivity(intent);
        }
    });
    exited = new TagButton((RadioButton) rootView.findViewById(R.id.exitedButton));
    exited.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            tagger.addTagToSong(currentMusicID, exited.getText().toString());
        }
    });
    calm = (RadioButton) rootView.findViewById(R.id.calmButton);
    calm.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            tagger.addTagToSong(currentMusicID, calm.getText().toString());
        }
    });

    return rootView;
}

From source file:com.kth.baasio.test.gcm.GCMIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *//*from w ww .java2 s . co m*/
private static void generateNotification(Context context, String message) {
    String body;
    try {
        LogUtils.LOGE(TAG, "GCM Received: " + message);
        BaasioPayload msg = JsonUtils.parse(message, BaasioPayload.class);
        if (msg == null) {
            return;
        }

        if (!ObjectUtils.isEmpty(msg.getAlert())) {
            body = msg.getAlert().replace("\\r\\n", "\n");
            if (!ObjectUtils.isEmpty(msg.getProperty(UnitTestConfig.PUSH_CUSTOM_FILED_KEY))) {
                body = body + "(" + msg.getProperty(UnitTestConfig.PUSH_CUSTOM_FILED_KEY).getTextValue() + ")";
            }

        } else {
            return;
        }
    } catch (BaasioRuntimeException e) {
        if (!ObjectUtils.isEmpty(message)) {
            body = message;
        } else {
            body = "Error";
        }

    }

    int icon = R.drawable.ic_launcher;
    long when = System.currentTimeMillis();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    Intent notificationIntent = new Intent(context, MainActivity.class);
    // set intent so it does not start a new activity
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

    Notification notification = new NotificationCompat.Builder(context).setWhen(when).setSmallIcon(icon)
            .setContentTitle(context.getString(R.string.app_name)).setContentText(body).setContentIntent(intent)
            .setTicker(body).setAutoCancel(true).getNotification();

    notificationManager.notify(UUID.randomUUID().hashCode(), notification);
}

From source file:com.syncedsynapse.kore2.ui.MoviesActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_show_remote:
        // Starts remote
        Intent launchIntent = new Intent(this, RemoteActivity.class).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        startActivity(launchIntent);//w w  w.ja v a2s  .  c o  m
        return true;
    case android.R.id.home:
        // Only respond to this if we are showing the movie details in portrait mode,
        // which can be checked by checking if selected movie != -1, in which case we
        // should go back to the previous fragment, which is the list.
        if (selectedMovieId != -1) {
            selectedMovieId = -1;
            selectedMovieTitle = null;
            setupActionBar(null);
            getSupportFragmentManager().popBackStack();
            return true;
        }
        break;
    default:
        break;
    }

    return super.onOptionsItemSelected(item);
}

From source file:net.frygo.findmybuddy.GCMIntentService.java

private static void generateNotification(Context context, String message) {

    Random rand = new Random();
    int x = rand.nextInt();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    String title = context.getString(R.string.app_name);
    Intent notificationIntent = new Intent(context, customlistview.class);
    notificationIntent.putExtra("alert", message);
    message = message + " would like to add you as friend";
    PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_CANCEL_CURRENT);

    Notification notification = new Notification(R.drawable.logo, message, System.currentTimeMillis());
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    notification.setLatestEventInfo(context, title, message, intent);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notificationManager.notify(x, notification);

    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    final PowerManager.WakeLock mWakelock = pm
            .newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, title);
    mWakelock.acquire();// w  w w .  jav  a  2  s .co m

    // Timer before putting Android Device to sleep mode.
    Timer timer = new Timer();
    TimerTask task = new TimerTask() {
        public void run() {
            mWakelock.release();
        }
    };
    timer.schedule(task, 5000);

}

From source file:com.syncedsynapse.kore2.ui.AddonsActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_show_remote:
        // Starts remote
        Intent launchIntent = new Intent(this, RemoteActivity.class).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        startActivity(launchIntent);//from   w w  w  .  j a v  a2s .co  m
        return true;
    case android.R.id.home:
        // Only respond to this if we are showing the details in portrait mode,
        // which can be checked by checking if selected movie != -1, in which case we
        // should go back to the previous fragment, which is the list.
        if (selectedAddonId != null) {
            selectedAddonId = null;
            selectedAddonTitle = null;
            setupActionBar(null);
            getSupportFragmentManager().popBackStack();
            return true;
        }
        break;
    default:
        break;
    }

    return super.onOptionsItemSelected(item);
}

From source file:com.baochu.androidassignment.notification.GcmIntentService.java

/** Issues a notification to inform the user */
private void sendNotification(String msg) {
    int msgId = Utils.getMessageId();
    mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
    Intent intent = new Intent(this, MainActivity.class);
    // set intent so it does not start a new activity
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    intent.putExtra(GcmActivity.EXTRA_MESSAGE, msg);
    PendingIntent contentIntent = PendingIntent.getActivity(this, msgId, intent, 0);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_gcm).setContentTitle(this.getString(R.string.app_name))
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg)
            .setDefaults(Notification.DEFAULT_SOUND).setAutoCancel(true);

    builder.setContentIntent(contentIntent);
    mNotificationManager.notify(msgId, builder.build());
}

From source file:at.ac.tuwien.caa.docscan.ui.StartActivity.java

private void startCamera() {

    Intent intent = new Intent(this, CameraActivity.class);
    intent.setFlags(//from  w w  w. ja  va2  s .c o m
            Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    startActivity(intent);

    finish();

}

From source file:com.example.jaecheol.gcm.GcmIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    Bundle extras = intent.getExtras();// w  w w  .j a  v a2 s  . co m
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
    // The getMessageType() intent parameter must be the intent you received
    // in your BroadcastReceiver.
    String messageType = gcm.getMessageType(intent);

    if (!extras.isEmpty()) { // has effect of unparcelling Bundle
        /*
         * Filter messages based on message type. Since it is likely that GCM will be
         * extended in the future with new message types, just ignore any message types you're
         * not interested in, or that you don't recognize.
         */
        if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
            sendNotification("Send error: " + extras.toString());
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
            sendNotification("Deleted messages on server: " + extras.toString());
            // If it's a regular GCM message, do some work.
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {

            //                String title = extras.getString("title");
            //                String message = extras.getString("message");
            //
            //                // This loop represents the service doing some work.
            //                for (int i = 0; i < 2; i++) {
            //                    Log.i(TAG, "Working... " + (i + 1)
            //                            + "/5 @ " + SystemClock.elapsedRealtime());
            //                    try {
            //                        Thread.sleep(2000);
            //                    } catch (InterruptedException e) {
            //                    }
            //                }
            //                Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime());
            // Post notification of received message.
            //                sendNotification("Received: " + extras.toString());
            sendNotification("Received: " + extras.getString("key1") + extras.getString("key2"));
            Log.i(TAG, "Received: " + extras.toString());

            Log.d("123", "START");
            Intent intent2 = new Intent(this.getApplicationContext(), MainActivity.class);
            intent2.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK
                    | Intent.FLAG_ACTIVITY_CLEAR_TOP);
            intent2.putExtra("data", extras);
            //intent2.setData(Uri.parse(extras.toString()));
            startActivity(intent2);
            Log.d("123", "END");

        }
    }
    // Release the wake lock provided by the WakefulBroadcastReceiver.
    GcmBroadcastReceiver.completeWakefulIntent(intent);
}

From source file:kookmin.cs.firstcoin.BP_order.GcmIntentService.java

private void sendNotification(String msg) {
    mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

    Map<String, String> msgMap = new HashMap<String, String>();
    String dataPair[] = msg.split(",");

    for (int i = 0; i < dataPair.length; i++) {
        String data = dataPair[i];
        String[] keyValue = data.split("=");
        keyValue[0] = keyValue[0].trim();
        msgMap.put(keyValue[0], keyValue[1]);
        Log.e("log_gcm_map", keyValue[0] + "," + keyValue[1]);
    }//  w  w w.  j  a v a2s.c  o  m

    String title = msgMap.get("title");
    String message = msgMap.get("message");

    Intent intent = new Intent(GcmIntentService.this, ActivityStart.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent contentIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis() / 1000,
            intent, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setVibrate(new long[] { 200, 1000, 200, 1000 }) // manifest 
            .setSmallIcon(R.drawable.ic_launcher_order_app_logo).setContentTitle(title)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(message)).setTicker(title)
            .setContentText(message).setContentIntent(contentIntent).setDefaults(0)
            .setLights(Color.GREEN, 1000, 100).setAutoCancel(true);

    // 
    PushWakeLock.acquireCpuWakeLock(this);

    mBuilder.setContentIntent(contentIntent);
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());

    PushWakeLock.releaseCpuLock();

}

From source file:com.memetro.android.oauth.OAuth.java

public JSONObject call(String controller, String action, Map<String, String> params) {
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(oauthServer + controller + "/" + action);

    try {/*from   w ww  . j  a  v a2  s  .c  o m*/
        // Add data
        httppost.setEntity(new UrlEncodedFormEntity(Map2NameValuePair(params)));

        // Execute Post
        HttpResponse response = httpclient.execute(httppost);

        // Catch headers
        int statusCode = response.getStatusLine().getStatusCode();
        lastHttpStatus = statusCode;
        if (statusCode != 200) {
            JSONObject returnJ = new JSONObject();
            returnJ.put("success", false);
            returnJ.put("data", new JSONArray());

            Log.d("Http Status Code", String.valueOf(statusCode));

            switch (statusCode) {
            case 401:
                if (refreshToken() && firstAuthCall) {
                    firstAuthCall = false;
                    Utils utils = new Utils();
                    params.put("access_token", utils.getToken(context));
                    return call(controller, action, params);
                }

                returnJ.put("message", context.getString(R.string.session_expired));
                Utils utils = new Utils();
                utils.setToken(context, "", "");
                Intent intent = new Intent(context, MainActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP
                        | Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(intent);
                return returnJ;
            case 404:
                returnJ.put("message", context.getString(R.string.action_not_found));
                return returnJ;
            case 500:
                returnJ.put("message", context.getString(R.string.server_error));
                return returnJ;
            default:
                returnJ.put("message", context.getString(R.string.internal_error));
                return returnJ;
            }
        }

        BufferedReader reader = new BufferedReader(
                new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
        String json = reader.readLine();
        JSONTokener tokener = new JSONTokener(json);

        return new JSONObject(tokener);

    } catch (ClientProtocolException e) {

        // TODO Auto-generated catch block

    } catch (JSONException e) {

        // TODO Auto-generated catch block

    } catch (IOException e) {

        // TODO Auto-generated catch block
    }
    return new JSONObject();
}