Example usage for android.content Intent FLAG_ACTIVITY_BROUGHT_TO_FRONT

List of usage examples for android.content Intent FLAG_ACTIVITY_BROUGHT_TO_FRONT

Introduction

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

Prototype

int FLAG_ACTIVITY_BROUGHT_TO_FRONT

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

Click Source Link

Document

This flag is not normally set by application code, but set for you by the system as described in the android.R.styleable#AndroidManifestActivity_launchMode launchMode documentation for the singleTask mode.

Usage

From source file:cz.muni.fi.japanesedictionary.parser.ParserService.java

/**
 * Downloads dictionaries./*from   ww w .j a  va2 s .  co m*/
 */

protected void onHandleIntent() {

    Log.i(LOG_TAG, "Creating parser service");

    Intent resultIntent = new Intent(getApplicationContext(), MainActivity.class);
    resultIntent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
    PendingIntent resultPendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, resultIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    mBuilder = new NotificationCompat.Builder(this).setAutoCancel(false).setOngoing(true)
            .setContentTitle(getString(R.string.dictionary_download_title))
            .setContentText(getString(R.string.dictionary_download_in_progress) + " (1/5)")
            .setSmallIcon(R.drawable.ic_notification).setProgress(100, 0, false).setContentInfo("0%")
            .setContentIntent(resultPendingIntent);

    startForeground(0, mNotification);
    mNotifyManager.notify(0, mBuilder.build());
    File storage;
    if (MainActivity.canWriteExternalStorage()) {
        // external storage available
        storage = getExternalCacheDir();
    } else {
        storage = getCacheDir();
    }
    if (storage == null) {
        throw new IllegalStateException("External storage isn't accessible");
    }
    // free sapce controll
    StatFs stat = new StatFs(storage.getPath());
    long bytesAvailable;
    if (Build.VERSION.SDK_INT < 18) {
        bytesAvailable = (long) stat.getBlockSize() * (long) stat.getAvailableBlocks();
    } else {
        bytesAvailable = stat.getAvailableBytes();
    }
    long megAvailable = bytesAvailable / 1048576;
    Log.d(LOG_TAG, "Megs free :" + megAvailable);
    if (megAvailable < 140) {
        mInternetReceiver = null;
        mNotEnoughSpace = true;
        stopSelf(mStartId);
        return;
    }

    this.registerReceiver(mInternetReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));

    SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
    boolean english = sharedPrefs.getBoolean("language_english", false);
    boolean french = sharedPrefs.getBoolean("language_french", false);
    boolean dutch = sharedPrefs.getBoolean("language_dutch", false);
    boolean german = sharedPrefs.getBoolean("language_german", false);
    boolean russian = sharedPrefs.getBoolean("language_russian", false);
    if (!english && !french && !dutch && !german && !russian) {
        Log.i(LOG_TAG, "Setting english as only translation language");
        SharedPreferences.Editor editor_lang = sharedPrefs.edit();
        editor_lang.putBoolean("language_english", true);
        editor_lang.commit();
    }

    String dictionaryPath;
    String kanjiDictPath;

    URL url;
    try {
        url = new URL(ParserService.DICTIONARY_PATH);
    } catch (MalformedURLException ex) {
        Log.e(LOG_TAG, "Error: creating url for downloading dictionary");
        return;
    }

    try {

        dictionaryPath = storage.getPath() + File.separator + "dictionary.zip";
        File outputFile = new File(dictionaryPath);
        if (outputFile.exists()) {
            outputFile.delete();
        }

        mDownloadJMDictFrom = url;
        mDownloadJMDictTo = outputFile;
        mDownloadingJMDict = true;
        mDownloadInProgress = true;

        // downloading kanjidict
        url = null;
        try {
            url = new URL(ParserService.KANJIDICT_PATH);
        } catch (MalformedURLException ex) {
            Log.e(LOG_TAG, "Error: creating url for downloading kanjidict2");
        }
        if (url != null) {
            kanjiDictPath = storage.getPath() + File.separator + "kanjidict.zip";
            File fileKanjidict = new File(kanjiDictPath);
            if (fileKanjidict.exists()) {
                fileKanjidict.delete();
            }
            mDownloadingKanjidic = false;
            mDownloadKanjidicFrom = url;
            mDownloadKanjidicTo = fileKanjidict;
        }

        mDownloadTatoebaIndicesFrom = new URL(ParserService.TATOEBA_INDICES_PATH);
        mDownloadTatoebaIndicesTo = new File(storage, "tatoeba-japanese.zip");
        if (mDownloadTatoebaIndicesTo.exists()) {
            mDownloadTatoebaIndicesTo.delete();
        }

        mDownloadTatoebaSentencesFrom = new URL(ParserService.TATOEBA_SENTENCES_PATH);
        mDownloadTatoebaSentencesTo = new File(storage, "tatoeba-translation.zip");
        if (mDownloadTatoebaSentencesTo.exists()) {
            mDownloadTatoebaSentencesTo.delete();
        }

        mDownloadKanjiVGFrom = new URL(ParserService.KANJIVG_PATH);
        mDownloadKanjiVGTo = new File(storage, "kanjivg.zip");
        if (mDownloadKanjiVGTo.exists()) {
            mDownloadKanjiVGTo.delete();
        }

        downloadDictionaries();

    } catch (MalformedURLException e) {
        Log.e(LOG_TAG, "MalformedURLException wrong format of URL: " + e.toString());
        stopSelf(mStartId);
    } catch (IOException e) {
        Log.e(LOG_TAG, "IOException downloading interrupted: " + e.toString());
        stopSelf(mStartId);
    } catch (Exception e) {
        e.printStackTrace();
        Log.e(LOG_TAG, "Exception: " + e.toString());
        stopSelf(mStartId);
    }

}

From source file:im.neon.activity.LoginActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (null == getIntent()) {
        Log.d(LOG_TAG, "## onCreate(): IN with no intent");
    } else {/*from w  w w.  j  a va 2 s  .  c om*/
        Log.d(LOG_TAG, "## onCreate(): IN with flags " + Integer.toHexString(getIntent().getFlags()));
    }

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_vector_login);

    // warn that the application has started.
    CommonActivityUtils.onApplicationStarted(this);

    Intent intent = getIntent();
    Bundle receivedBundle = (null != intent) ? getIntent().getExtras() : null;

    // resume the application
    if (null != receivedBundle) {
        if (receivedBundle.containsKey(VectorUniversalLinkReceiver.EXTRA_UNIVERSAL_LINK_URI)) {
            mUniversalLinkUri = receivedBundle
                    .getParcelable(VectorUniversalLinkReceiver.EXTRA_UNIVERSAL_LINK_URI);
            Log.d(LOG_TAG, "## onCreate() Login activity started by universal link");
            // activity has been launched from an universal link
        } else if (receivedBundle.containsKey(VectorRegistrationReceiver.EXTRA_EMAIL_VALIDATION_PARAMS)) {
            Log.d(LOG_TAG, "## onCreate() Login activity started by email verification for registration");
            processEmailValidationExtras(receivedBundle);
        }
    }
    // already registered
    if (hasCredentials()) {
        if ((null != intent) && (intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) == 0) {
            Log.d(LOG_TAG, "## onCreate(): goToSplash because the credentials are already provided.");
            goToSplash();
        } else {
            // detect if the application has already been started
            if (null == EventStreamService.getInstance()) {
                Log.d(LOG_TAG,
                        "## onCreate(): goToSplash with credentials but there is no event stream service.");
                goToSplash();
            } else {
                Log.d(LOG_TAG, "## onCreate(): close the login screen because it is a temporary task");
            }
        }

        finish();
        return;
    }

    // bind UI widgets
    mLoginMaskView = (RelativeLayout) findViewById(R.id.flow_ui_mask_login);

    // login
    mLoginEmailTextView = (EditText) findViewById(R.id.login_user_name);
    mLoginPhoneNumber = (EditText) findViewById(R.id.login_phone_number_value);
    mLoginPhoneNumberCountryCode = (EditText) findViewById(R.id.login_phone_number_country);
    mLoginPasswordTextView = (EditText) findViewById(R.id.login_password);

    // account creation
    mCreationUsernameTextView = (EditText) findViewById(R.id.creation_your_name);
    mCreationPassword1TextView = (EditText) findViewById(R.id.creation_password1);
    mCreationPassword2TextView = (EditText) findViewById(R.id.creation_password2);

    // account creation - three pid
    mThreePidInstructions = (TextView) findViewById(R.id.instructions);
    mEmailAddress = (EditText) findViewById(R.id.registration_email);
    mPhoneNumberLayout = findViewById(R.id.registration_phone_number);
    mPhoneNumber = (EditText) findViewById(R.id.registration_phone_number_value);
    mPhoneNumberCountryCode = (EditText) findViewById(R.id.registration_phone_number_country);
    mSubmitThreePidButton = (Button) findViewById(R.id.button_submit);
    mSkipThreePidButton = (Button) findViewById(R.id.button_skip);

    // forgot password
    mPasswordForgottenTxtView = (TextView) findViewById(R.id.login_forgot_password);
    mForgotEmailTextView = (TextView) findViewById(R.id.forget_email_address);
    mForgotPassword1TextView = (EditText) findViewById(R.id.forget_new_password);
    mForgotPassword2TextView = (EditText) findViewById(R.id.forget_confirm_new_password);

    mHomeServerOptionLayout = findViewById(R.id.homeserver_layout);
    mHomeServerText = (EditText) findViewById(R.id.login_matrix_server_url);
    mIdentityServerText = (EditText) findViewById(R.id.login_identity_url);

    mLoginButton = (Button) findViewById(R.id.button_login);
    mRegisterButton = (Button) findViewById(R.id.button_register);
    mForgotPasswordButton = (Button) findViewById(R.id.button_reset_password);
    mForgotValidateEmailButton = (Button) findViewById(R.id.button_forgot_email_validate);

    mHomeServerUrlsLayout = findViewById(R.id.login_matrix_server_options_layout);
    mUseCustomHomeServersCheckbox = (CheckBox) findViewById(R.id.display_server_url_expand_checkbox);

    mProgressTextView = (TextView) findViewById(R.id.flow_progress_message_textview);

    mMainLayout = findViewById(R.id.main_input_layout);
    mButtonsView = findViewById(R.id.login_actions_bar);

    if (null != savedInstanceState) {
        restoreSavedData(savedInstanceState);
    } else {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(LoginActivity.this);
        mHomeServerText.setText(preferences.getString(HOME_SERVER_URL_PREF,
                getResources().getString(R.string.default_hs_server_url)));
        mIdentityServerText.setText(preferences.getString(IDENTITY_SERVER_URL_PREF,
                getResources().getString(R.string.default_identity_server_url)));
    }

    // trap the UI events
    mLoginMaskView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
        }
    });

    mLoginButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            onLoginClick();
        }
    });

    // account creation handler
    mRegisterButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mIsUserNameAvailable = false;
            onRegisterClick(true);
        }
    });

    // forgot password button
    mForgotPasswordButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            onForgotPasswordClick();
        }
    });

    mForgotValidateEmailButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onForgotOnEmailValidated(getHsConfig());
        }
    });

    // home server input validity: if the user taps on the next / done button
    mHomeServerText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                onHomeServerUrlUpdate();
                return true;
            }

            return false;
        }
    });

    // home server input validity: when focus changes
    mHomeServerText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        public void onFocusChange(View v, boolean hasFocus) {
            if (!hasFocus) {
                onHomeServerUrlUpdate();
            }
        }
    });

    // identity server input validity: if the user taps on the next / done button
    mIdentityServerText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                onIdentityserverUrlUpdate();
                return true;
            }

            return false;
        }
    });

    // identity server input validity: when focus changes
    mIdentityServerText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        public void onFocusChange(View v, boolean hasFocus) {
            if (!hasFocus) {
                onIdentityserverUrlUpdate();
            }
        }
    });

    // "forgot password?" handler
    mPasswordForgottenTxtView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mMode = MODE_FORGOT_PASSWORD;
            refreshDisplay();
        }
    });

    mUseCustomHomeServersCheckbox.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mUseCustomHomeServersCheckbox.post(new Runnable() {
                @Override
                public void run() {
                    // reset the HS urls.
                    mHomeServerUrl = null;
                    mIdentityServerUrl = null;
                    onIdentityserverUrlUpdate();
                    onHomeServerUrlUpdate();
                    refreshDisplay();
                }
            });
        }
    });

    mLoginPhoneNumberHandler = new PhoneNumberHandler(this, mLoginPhoneNumber, mLoginPhoneNumberCountryCode,
            PhoneNumberHandler.DISPLAY_COUNTRY_ISO_CODE, REQUEST_LOGIN_COUNTRY);
    mLoginPhoneNumberHandler.setCountryCode(PhoneNumberUtils.getCountryCode(this));
    mRegistrationPhoneNumberHandler = new PhoneNumberHandler(this, mPhoneNumber, mPhoneNumberCountryCode,
            PhoneNumberHandler.DISPLAY_COUNTRY_ISO_CODE, REQUEST_REGISTRATION_COUNTRY);

    refreshDisplay();

    // reset the badge counter
    CommonActivityUtils.updateBadgeCount(this, 0);

    mHomeServerText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(LoginActivity.this);
            SharedPreferences.Editor editor = preferences.edit();
            editor.putString(HOME_SERVER_URL_PREF, mHomeServerText.getText().toString().trim());
            editor.apply();
        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    });

    mIdentityServerText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(LoginActivity.this);
            SharedPreferences.Editor editor = preferences.edit();
            editor.putString(IDENTITY_SERVER_URL_PREF, mIdentityServerText.getText().toString().trim());
            editor.apply();
        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    });

    // set the handler used by the register to poll the server response
    mHandler = new Handler(getMainLooper());
}

From source file:org.cowboycoders.cyclismo.TrackListActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setVolumeControlStream(TextToSpeech.Engine.DEFAULT_STREAM);
    setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
    setContentView(R.layout.track_list);

    sharedPreferences = getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE);

    trackRecordingServiceConnection = new TrackRecordingServiceConnection(this, bindChangedCallback);

    trackController = new TrackController(this, trackRecordingServiceConnection, true, recordListener,
            stopListener, -1);/*w ww  . jav  a  2  s.c o  m*/

    listView = (ListView) findViewById(R.id.track_list);
    listView.setEmptyView(findViewById(R.id.track_list_empty_view));
    listView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Intent intent = IntentUtils.newIntent(TrackListActivity.this, TrackDetailActivity.class)
                    .putExtra(TrackDetailActivity.EXTRA_TRACK_ID, id);
            if (isRecording() && id == recordingTrackId) {
                Log.d(TAG, "recordingTrackId: " + recordingTrackId);
                recordingCourseId = PreferencesUtils.getLong(TrackListActivity.this,
                        R.string.recording_course_track_id_key);
                intent.putExtra(TrackDetailActivity.EXTRA_COURSE_TRACK_ID, recordingCourseId)
                        .putExtra(TrackDetailActivity.EXTRA_USE_COURSE_PROVIDER, false);
            }
            intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
            intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);
        }
    });
    resourceCursorAdapter = new ResourceCursorAdapter(this, R.layout.list_item, null, 0) {
        @Override
        public void bindView(View view, Context context, Cursor cursor) {
            int idIndex = cursor.getColumnIndex(TracksColumns._ID);
            int iconIndex = cursor.getColumnIndex(TracksColumns.ICON);
            int nameIndex = cursor.getColumnIndex(TracksColumns.NAME);
            int categoryIndex = cursor.getColumnIndex(TracksColumns.CATEGORY);
            int totalTimeIndex = cursor.getColumnIndexOrThrow(TracksColumns.TOTALTIME);
            int totalDistanceIndex = cursor.getColumnIndexOrThrow(TracksColumns.TOTALDISTANCE);
            int startTimeIndex = cursor.getColumnIndexOrThrow(TracksColumns.STARTTIME);
            int descriptionIndex = cursor.getColumnIndex(TracksColumns.DESCRIPTION);

            boolean isRecording = cursor.getLong(idIndex) == recordingTrackId;
            int iconId = TrackIconUtils.getIconDrawable(cursor.getString(iconIndex));
            String name = cursor.getString(nameIndex);
            String totalTime = StringUtils.formatElapsedTime(cursor.getLong(totalTimeIndex));
            String totalDistance = StringUtils.formatDistance(TrackListActivity.this,
                    cursor.getDouble(totalDistanceIndex), metricUnits);
            long startTime = cursor.getLong(startTimeIndex);
            String startTimeDisplay = StringUtils.formatDateTime(context, startTime).equals(name) ? null
                    : StringUtils.formatRelativeDateTime(context, startTime);

            ListItemUtils.setListItem(TrackListActivity.this, view, isRecording, recordingTrackPaused, iconId,
                    R.string.icon_track, name, cursor.getString(categoryIndex), totalTime, totalDistance,
                    startTimeDisplay, cursor.getString(descriptionIndex));
        }
    };
    listView.setAdapter(resourceCursorAdapter);
    ApiAdapterFactory.getApiAdapter().configureListViewContextualMenu(this, listView,
            contextualActionModeCallback);

    getSupportLoaderManager().initLoader(0, null, new LoaderCallbacks<Cursor>() {
        @Override
        public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
            updateCurrentUserId();
            long userId = currentUserId.get();
            String selection = TracksColumns.OWNER + "=?";
            String[] args = new String[] { Long.toString(userId) };
            return new CursorLoader(TrackListActivity.this, TracksColumns.CONTENT_URI, PROJECTION, selection,
                    args, TracksColumns._ID + " DESC");
        }

        @Override
        public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
            resourceCursorAdapter.swapCursor(cursor);
        }

        @Override
        public void onLoaderReset(Loader<Cursor> loader) {
            resourceCursorAdapter.swapCursor(null);
        }
    });
    trackDataHub = TrackDataHub.newInstance(this);
    if (savedInstanceState != null) {
        startGps = savedInstanceState.getBoolean(START_GPS_KEY);
    }
    showStartupDialogs();
}

From source file:org.cowboycoders.cyclisimo.UserListActivity.java

private AsyncTask<Object, Integer, User> getSyncSettingsTask() {
    AsyncTask<Object, Integer, User> task = new AsyncTask<Object, Integer, User>() {

        @Override/*from   w  w  w . j a  v a2  s  .  c  om*/
        protected User doInBackground(Object... params) {

            Long newId = (Long) params[0];

            if (newId == -1L) {
                return null;
            }

            final long oldId = PreferencesUtils.getLong(UserListActivity.this,
                    R.string.settings_select_user_current_selection_key);

            PreferencesUtils.setLong(UserListActivity.this, R.string.settings_select_user_current_selection_key,
                    newId);

            // save previous users settings
            if (oldId != -1L) {
                User user = loadUser(oldId);
                SettingsUtils.saveSettings(UserListActivity.this, user);
            }

            User user = loadUser(newId);
            SettingsUtils.restoreSettings(UserListActivity.this, user);
            return user;

        }

        @Override
        protected void onPostExecute(User result) {
            Context context = UserListActivity.this;
            UserListActivity.this.finish();
            if (result == null) {
                Intent intent = IntentUtils.newIntent(context, UserListActivity.class);
                UserListActivity.this.startActivity(intent);
            } else {
                Intent intent = IntentUtils.newIntent(UserListActivity.this, TrackListActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
                intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);
                String unformated = getString(R.string.user_list_new_user_selected);
                Toast.makeText(UserListActivity.this, String.format(unformated, result.getName()),
                        Toast.LENGTH_SHORT).show();
            }
        }

    };

    return task;
}

From source file:com.sentaroh.android.TaskAutomation.TaskManager.java

static final public void showMessageDialog(TaskManagerParms taskMgrParms, EnvironmentParms envParms,
        CommonUtilities util, String group, String task, String action, String dialog_id, String msg_type,
        String msg_text) {/*  w ww .  ja  v  a  2  s.  c om*/
    Intent in_b = new Intent(taskMgrParms.context.getApplicationContext(), ActivityMessage.class);
    //          in_b.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TOP);
    in_b.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK
            | Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
    in_b.putExtra(MESSAGE_DIALOG_MESSAGE_KEY_GROUP, group);
    in_b.putExtra(MESSAGE_DIALOG_MESSAGE_KEY_TASK, task);
    in_b.putExtra(MESSAGE_DIALOG_MESSAGE_KEY_ACTION, action);
    in_b.putExtra(MESSAGE_DIALOG_MESSAGE_KEY_DIALOG_ID, dialog_id);
    in_b.putExtra(MESSAGE_DIALOG_MESSAGE_KEY_TYPE, msg_type);
    in_b.putExtra(MESSAGE_DIALOG_MESSAGE_KEY_TEXT, msg_text);

    taskMgrParms.context.startActivity(in_b);
}

From source file:org.cowboycoders.cyclisimo.TrackListActivity.java

private void restart() {
    Intent intent = IntentUtils.newIntent(this, TrackListActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
    intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    this.finish();
    this.startActivity(intent);
}

From source file:pt.aptoide.backupapps.Aptoide.java

private void cleanAptoideIntent() {
    Intent aptoide = new Intent(this, Aptoide.class);
    aptoide.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(aptoide);//ww  w .j av  a 2s.co  m
}

From source file:es.javocsoft.android.lib.toolbox.ToolBox.java

/**
 * Creates a system notification.//  w w  w. ja  v  a  2  s .  co m
 *    
 * @param context            Context.
 * @param notSound            Enable or disable the sound
 * @param notSoundRawId         Custom raw sound id. If enabled and not set 
 *                         default notification sound will be used. Set to -1 to 
 *                         default system notification.
 * @param multipleNot         Setting to True allows showing multiple notifications.
 * @param groupMultipleNotKey   If is set, multiple notifications can be grupped by this key.
 * @param notAction            Action for this notification
 * @param notTitle            Title
 * @param notMessage         Message
 * @param notClazz            Class to be executed
 * @param extras            Extra information
 * 
 */
public static void notification_generate(Context context, boolean notSound, int notSoundRawId,
        boolean multipleNot, String groupMultipleNotKey, String notAction, String notTitle, String notMessage,
        Class<?> notClazz, Bundle extras, boolean wakeUp) {

    try {
        int iconResId = notification_getApplicationIcon(context);
        long when = System.currentTimeMillis();

        Notification notification = new Notification(iconResId, notMessage, when);

        // Hide the notification after its selected
        notification.flags |= Notification.FLAG_AUTO_CANCEL;

        if (notSound) {
            if (notSoundRawId > 0) {
                try {
                    notification.sound = Uri.parse("android.resource://"
                            + context.getApplicationContext().getPackageName() + "/" + notSoundRawId);
                } catch (Exception e) {
                    if (LOG_ENABLE) {
                        Log.w(TAG, "Custom sound " + notSoundRawId + "could not be found. Using default.");
                    }
                    notification.defaults |= Notification.DEFAULT_SOUND;
                    notification.sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
                }
            } else {
                notification.defaults |= Notification.DEFAULT_SOUND;
                notification.sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            }
        }

        Intent notificationIntent = new Intent(context, notClazz);
        notificationIntent.setAction(notClazz.getName() + "." + notAction);
        if (extras != null) {
            notificationIntent.putExtras(extras);
        }

        //Set intent so it does not start a new activity
        //
        //Notes:
        //   - The flag FLAG_ACTIVITY_SINGLE_TOP makes that only one instance of the activity exists(each time the
        //      activity is summoned no onCreate() method is called instead, onNewIntent() is called.
        //  - If we use FLAG_ACTIVITY_CLEAR_TOP it will make that the last "snapshot"/TOP of the activity it will 
        //     be this called this intent. We do not want this because the HOME button will call this "snapshot". 
        //     To avoid this behaviour we use FLAG_ACTIVITY_BROUGHT_TO_FRONT that simply takes to foreground the 
        //     activity.
        //
        //See http://developer.android.com/reference/android/content/Intent.html           
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP);

        PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        int REQUEST_UNIQUE_ID = 0;
        if (multipleNot) {
            if (groupMultipleNotKey != null && groupMultipleNotKey.length() > 0) {
                REQUEST_UNIQUE_ID = groupMultipleNotKey.hashCode();
            } else {
                if (random == null) {
                    random = new Random();
                }
                REQUEST_UNIQUE_ID = random.nextInt();
            }
            PendingIntent.getActivity(context, REQUEST_UNIQUE_ID, notificationIntent,
                    PendingIntent.FLAG_ONE_SHOT);
        }

        notification.setLatestEventInfo(context, notTitle, notMessage, intent);

        //This makes the device to wake-up is is idle with the screen off.
        if (wakeUp) {
            powersaving_wakeUp(context);
        }

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

        //We check if the sound is disabled to enable just for a moment
        AudioManager amanager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
        int previousAudioMode = amanager.getRingerMode();
        ;
        if (notSound && previousAudioMode != AudioManager.RINGER_MODE_NORMAL) {
            amanager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
        }

        notificationManager.notify(REQUEST_UNIQUE_ID, notification);

        //We restore the sound setting
        if (previousAudioMode != AudioManager.RINGER_MODE_NORMAL) {
            //We wait a little so sound is played
            try {
                Thread.sleep(3000);
            } catch (Exception e) {
            }
        }
        amanager.setRingerMode(previousAudioMode);

        Log.d(TAG, "Android Notification created.");

    } catch (Exception e) {
        if (LOG_ENABLE)
            Log.e(TAG, "The notification could not be created (" + e.getMessage() + ")", e);
    }
}

From source file:com.android.leanlauncher.LauncherTransitionable.java

@Override
protected void onNewIntent(Intent intent) {
    long startTime = 0;
    if (DEBUG_RESUME_TIME) {
        startTime = System.currentTimeMillis();
    }// ww  w . ja va 2s .  com
    super.onNewIntent(intent);

    // Close the menu
    if (Intent.ACTION_MAIN.equals(intent.getAction())) {
        // also will cancel mWaitingForResult.
        closeSystemDialogs();

        final boolean alreadyOnHome = mHasFocus && ((intent.getFlags()
                & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);

        if (mWorkspace == null) {
            // Can be cases where mWorkspace is null, this prevents a NPE
            return;
        }
        // In all these cases, only animate if we're already on home
        mWorkspace.exitWidgetResizeMode();
        mWorkspace.requestFocus();

        exitSpringLoadedDragMode();

        // If we are already on home, then just animate back to the workspace,
        // otherwise, just wait until onResume to set the state back to Workspace
        if (alreadyOnHome) {
            showWorkspace(true);
        } else {
            mOnResumeState = State.WORKSPACE;
        }

        final View v = getWindow().peekDecorView();
        if (v != null && v.getWindowToken() != null) {
            InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
        }

        // Reset the apps customize page
        if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
            mAppsCustomizeTabHost.reset();
        }
    }

    if (DEBUG_RESUME_TIME) {
        Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
    }
}

From source file:com.android.launcher2.Launcher.java

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);

    // Close the menu
    if (Intent.ACTION_MAIN.equals(intent.getAction())) {
        // also will cancel mWaitingForResult.
        closeSystemDialogs();/*from  w  w w.ja v  a2 s. c  om*/

        final boolean alreadyOnHome = ((intent.getFlags()
                & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);

        Runnable processIntent = new Runnable() {
            public void run() {
                if (mWorkspace == null) {
                    // Can be cases where mWorkspace is null, this prevents a NPE
                    return;
                }
                Folder openFolder = mWorkspace.getOpenFolder();
                // In all these cases, only animate if we're already on home
                mWorkspace.exitWidgetResizeMode();
                if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive()
                        && openFolder == null) {
                    mWorkspace.moveToDefaultScreen(true);
                }

                closeFolder();
                exitSpringLoadedDragMode();

                // If we are already on home, then just animate back to the workspace,
                // otherwise, just wait until onResume to set the state back to Workspace
                if (alreadyOnHome) {
                    showWorkspace(true);
                } else {
                    mOnResumeState = State.WORKSPACE;
                }

                final View v = getWindow().peekDecorView();
                if (v != null && v.getWindowToken() != null) {
                    InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
                }

                // Reset AllApps to its initial state
                if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
                    mAppsCustomizeTabHost.reset();
                }
            }
        };

        if (alreadyOnHome && !mWorkspace.hasWindowFocus()) {
            // Delay processing of the intent to allow the status bar animation to finish
            // first in order to avoid janky animations.
            mWorkspace.postDelayed(processIntent, 350);
        } else {
            // Process the intent immediately.
            processIntent.run();
        }

    }
}