Example usage for android.content Intent FLAG_ACTIVITY_MULTIPLE_TASK

List of usage examples for android.content Intent FLAG_ACTIVITY_MULTIPLE_TASK

Introduction

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

Prototype

int FLAG_ACTIVITY_MULTIPLE_TASK

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

Click Source Link

Document

This flag is used to create a new task and launch an activity into it.

Usage

From source file:info.papdt.express.helper.ui.SettingsActivity.java

public static void launchActivity(Activity mActivity, int flag) {
    Intent intent = new Intent(mActivity, SettingsActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
    intent.putExtra(EXTRA_FLAG, flag);//  w w w  .ja v  a  2 s.  c o  m
    mActivity.startActivity(intent);
}

From source file:com.farmerbb.taskbar.activity.KeyboardShortcutActivity.java

@SuppressWarnings("deprecation")
@Override//w w  w  .jav  a2  s  . co m
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Perform different actions depending on how this activity was launched
    switch (getIntent().getAction()) {
    case Intent.ACTION_MAIN:
        Intent selector = getIntent().getSelector();
        Set<String> categories = selector != null ? selector.getCategories() : getIntent().getCategories();

        if (categories.contains(Intent.CATEGORY_APP_MAPS)) {
            SharedPreferences pref = U.getSharedPreferences(this);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && pref.getBoolean("freeform_hack", false)
                    && isInMultiWindowMode() && !FreeformHackHelper.getInstance().isFreeformHackActive()) {
                U.startFreeformHack(this, false, false);
            }

            Intent startStopIntent;

            if (pref.getBoolean("taskbar_active", false))
                startStopIntent = new Intent("com.farmerbb.taskbar.QUIT");
            else
                startStopIntent = new Intent("com.farmerbb.taskbar.START");

            startStopIntent.setPackage(BuildConfig.APPLICATION_ID);
            sendBroadcast(startStopIntent);
        } else if (categories.contains(Intent.CATEGORY_APP_CALENDAR))
            U.lockDevice(this);

        break;
    case Intent.ACTION_ASSIST:
        if (U.isServiceRunning(this, StartMenuService.class)) {
            LocalBroadcastManager.getInstance(this)
                    .sendBroadcast(new Intent("com.farmerbb.taskbar.TOGGLE_START_MENU"));
        } else {
            Intent intent = new Intent("com.google.android.googlequicksearchbox.TEXT_ASSIST");
            if (intent.resolveActivity(getPackageManager()) == null)
                intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);

            if (intent.resolveActivity(getPackageManager()) != null) {
                SharedPreferences pref = U.getSharedPreferences(this);
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && pref.getBoolean("freeform_hack", false)
                        && isInMultiWindowMode()) {
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
                    U.launchAppMaximized(getApplicationContext(), intent);
                } else {
                    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(intent);
                }
            }
        }
        break;
    }

    finish();
}

From source file:ar.org.fsadosky.iptablesmanager.activity.MainActivity.java

private void goToGooglePlay() {
    Uri uri = Uri.parse("market://details?id=" + getPackageName());
    Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
    // To count with Play market backstack, After pressing back button,
    // to taken back to our application, we need to add following flags to intent.
    goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET
            | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
    try {//from  ww w.  j  a  va 2  s .  co m
        startActivity(goToMarket);
    } catch (ActivityNotFoundException e) {
        startActivity(new Intent(Intent.ACTION_VIEW,
                Uri.parse("http://play.google.com/store/apps/details?id=" + getPackageName())));
    }
}

From source file:com.vixir.finalproject.perfectday.fragment.MoreInfoFragment.java

@OnClick(R.id.rate_the_app)
public void onClickRateTheApp() {
    Uri uri = Uri.parse("market://details?id=" + getContext().getPackageName());
    Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
    goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_NEW_DOCUMENT
            | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
    try {/*from  w  ww.j  ava2 s. c  o m*/
        startActivity(goToMarket);
    } catch (ActivityNotFoundException e) {
        startActivity(new Intent(Intent.ACTION_VIEW,
                Uri.parse("http://play.google.com/store/apps/details?id=" + getContext().getPackageName())));
    }
}

From source file:com.owncloud.android.ui.dialog.RateMeDialog.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Create a view by inflating desired layout
    View v = inflater.inflate(R.layout.rate_me_dialog, container, false);

    Button rateNowButton = v.findViewById(R.id.button_rate_now);
    Button laterButton = v.findViewById(R.id.button_later);
    Button noThanksButton = v.findViewById(R.id.button_no_thanks);
    TextView titleView = v.findViewById(R.id.rate_me_dialog_title_view);

    titleView.setText(String.format(getString(R.string.rate_dialog_title), getString(R.string.app_name)));

    rateNowButton.setOnClickListener(new View.OnClickListener() {
        @Override/*ww  w  .  j  a  v  a  2s. c  o  m*/
        public void onClick(View v) {
            String packageName = getArguments().getString(APP_PACKAGE_NAME);
            Uri uri = Uri.parse(MARKET_DETAILS_URI + packageName);
            Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);

            /// To count with Play market back stack, After pressing back button,
            /// to taken back to our application, we need to add following flags to intent.
            int flags = Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_MULTIPLE_TASK;
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                flags |= Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
            } else {
                flags |= Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET;
            }
            goToMarket.addFlags(flags);

            try {
                startActivity(goToMarket);
            } catch (ActivityNotFoundException e) {
                getActivity()
                        .startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(PLAY_STORE_URI + packageName)));
            }
            dialog.dismiss();
        }
    });

    laterButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            SharedPreferences preferences = getActivity().getSharedPreferences(AppRater.APP_RATER_PREF_TITLE,
                    0);
            SharedPreferences.Editor editor = preferences.edit();
            editor.putLong(AppRater.APP_RATER_PREF_DATE_NEUTRAL, System.currentTimeMillis());
            editor.apply();
            dialog.dismiss();
        }
    });

    noThanksButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            SharedPreferences preferences = getActivity().getSharedPreferences(AppRater.APP_RATER_PREF_TITLE,
                    0);
            SharedPreferences.Editor editor = preferences.edit();
            editor.putBoolean(AppRater.APP_RATER_PREF_DONT_SHOW, true);
            editor.apply();
            dialog.dismiss();
        }
    });

    return v;
}

From source file:com.atahani.telepathy.ui.fragment.AboutDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    LayoutInflater inflater = getActivity().getLayoutInflater();
    View customLayout = inflater.inflate(R.layout.fragment_about_dialog, null);
    //config app version information
    mAppPreferenceTools = new AppPreferenceTools(TApplication.applicationContext);
    AppCompatTextView txAndroidAppVerInfo = (AppCompatTextView) customLayout
            .findViewById(R.id.tx_android_ver_info);
    txAndroidAppVerInfo.setText(String.format(getString(R.string.label_telepathy_for_android),
            mAppPreferenceTools.getTheLastAppVersion()));
    txAndroidAppVerInfo.setOnClickListener(new View.OnClickListener() {
        @Override/*w w  w .java2s  .c o  m*/
        public void onClick(View v) {
            try {
                //open browser to navigate telepathy website
                Uri telepathyWebSiteUri = Uri.parse("https://github.com/atahani/telepathy-android.git");
                startActivity(new Intent(Intent.ACTION_VIEW, telepathyWebSiteUri));
                ((TelepathyBaseActivity) getActivity()).setAnimationOnStart();
            } catch (Exception ex) {
                AndroidUtilities.processApplicationError(ex, true);
                if (isAdded() && getActivity() != null) {
                    Snackbar.make(getActivity().findViewById(android.R.id.content),
                            getString(R.string.re_action_internal_app_error), Snackbar.LENGTH_LONG).show();
                }
            }
        }
    });
    //config google play store link
    AppCompatTextView txRateUsOnGooglePlayStore = (AppCompatTextView) customLayout
            .findViewById(R.id.tx_rate_us_on_play_store);
    txRateUsOnGooglePlayStore.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //navigate to market for rate application
            Uri uri = Uri.parse("market://details?id=" + TApplication.applicationContext.getPackageName());
            Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
            // To count with Play market backstack, After pressing back button,
            // to taken back to our application, we need to add following flags to intent.
            goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
            try {
                startActivity(goToMarket);
                ((TelepathyBaseActivity) getActivity()).setAnimationOnStart();
            } catch (ActivityNotFoundException e) {
                startActivity(
                        new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id="
                                + TApplication.applicationContext.getPackageName())));
            }
        }
    });
    //config twitter link
    AppCompatTextView txTwitterLink = (AppCompatTextView) customLayout.findViewById(R.id.tx_twitter_telepathy);
    txTwitterLink.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                // If Twitter app is not installed, start browser.
                Uri twitterUri = Uri.parse("http://twitter.com/");
                startActivity(new Intent(Intent.ACTION_VIEW, twitterUri));
                ((TelepathyBaseActivity) getActivity()).setAnimationOnStart();
            } catch (Exception ex) {
                AndroidUtilities.processApplicationError(ex, true);
                if (isAdded() && getActivity() != null) {
                    Snackbar.make(getActivity().findViewById(android.R.id.content),
                            getString(R.string.re_action_internal_app_error), Snackbar.LENGTH_LONG).show();
                }
            }
        }
    });
    //config privacy link
    AppCompatTextView txPrivacyLink = (AppCompatTextView) customLayout.findViewById(R.id.tx_privacy);
    txPrivacyLink.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                //open browser to navigate privacy link
                Uri privacyPolicyUri = Uri
                        .parse("https://github.com/atahani/telepathy-android/blob/master/LICENSE.md");
                startActivity(new Intent(Intent.ACTION_VIEW, privacyPolicyUri));
                ((TelepathyBaseActivity) getActivity()).setAnimationOnStart();
            } catch (Exception ex) {
                AndroidUtilities.processApplicationError(ex, true);
                if (isAdded() && getActivity() != null) {
                    Snackbar.make(getActivity().findViewById(android.R.id.content),
                            getString(R.string.re_action_internal_app_error), Snackbar.LENGTH_LONG).show();
                }
            }
        }
    });
    //config report bug to open mail application and send bugs report
    AppCompatTextView txReportBug = (AppCompatTextView) customLayout.findViewById(R.id.tx_report_bug);
    txReportBug.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                final Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
                emailIntent.setType("plain/text");
                emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
                        getString(R.string.label_report_bug_email_subject));
                emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailDeviceInformation());
                emailIntent.setData(Uri.parse("mailto:" + getString(R.string.telepathy_report_bug_email)));
                startActivity(Intent.createChooser(emailIntent,
                        getString(R.string.label_report_bug_choose_mail_app)));
                ((TelepathyBaseActivity) getActivity()).setAnimationOnStart();
            } catch (Exception ex) {
                AndroidUtilities.processApplicationError(ex, true);
                if (isAdded() && getActivity() != null) {
                    Snackbar.make(getActivity().findViewById(android.R.id.content),
                            getString(R.string.re_action_internal_app_error), Snackbar.LENGTH_LONG).show();
                }
            }
        }
    });
    //config the about footer image view
    AboutFooterImageView footerImageView = (AboutFooterImageView) customLayout
            .findViewById(R.id.im_delete_user_account);
    footerImageView.setTouchOnImageViewEventListener(new AboutFooterImageView.touchOnImageViewEventListener() {
        @Override
        public void onDoubleTab() {
            try {
                //confirm account delete via alert dialog
                final AlertDialog.Builder confirmAccountDeleteDialog = new AlertDialog.Builder(getActivity());
                confirmAccountDeleteDialog.setTitle(getString(R.string.label_delete_user_account));
                confirmAccountDeleteDialog
                        .setMessage(getString(R.string.label_delete_user_account_description));
                confirmAccountDeleteDialog.setNegativeButton(getString(R.string.action_no), null);
                confirmAccountDeleteDialog.setPositiveButton(getString(R.string.action_yes),
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                //ok to delete account action
                                final ProgressDialog progressDialog = new ProgressDialog(getActivity());
                                progressDialog.setCancelable(false);
                                progressDialog.setCanceledOnTouchOutside(false);
                                progressDialog
                                        .setMessage(getString(R.string.re_action_on_deleting_user_account));
                                progressDialog.show();
                                TService tService = ((TelepathyBaseActivity) getActivity()).getTService();
                                tService.deleteUserAccount(new Callback<TOperationResultModel>() {
                                    @Override
                                    public void success(TOperationResultModel tOperationResultModel,
                                            Response response) {
                                        if (getActivity() != null && isAdded()) {
                                            //broad cast to close all of the realm  instance
                                            Intent intentToCloseRealm = new Intent(
                                                    Constants.TELEPATHY_BASE_ACTIVITY_INTENT_FILTER);
                                            intentToCloseRealm.putExtra(Constants.ACTION_TO_DO_PARAM,
                                                    Constants.CLOSE_REALM_DB);
                                            LocalBroadcastManager.getInstance(getActivity())
                                                    .sendBroadcastSync(intentToCloseRealm);
                                            mAppPreferenceTools.removeAllOfThePref();
                                            //                                 for sign out google first build GoogleAPIClient
                                            final GoogleApiClient googleApiClient = new GoogleApiClient.Builder(
                                                    TApplication.applicationContext)
                                                            .addApi(Auth.GOOGLE_SIGN_IN_API).build();
                                            googleApiClient.connect();
                                            googleApiClient.registerConnectionCallbacks(
                                                    new GoogleApiClient.ConnectionCallbacks() {
                                                        @Override
                                                        public void onConnected(Bundle bundle) {
                                                            Auth.GoogleSignInApi.signOut(googleApiClient)
                                                                    .setResultCallback(
                                                                            new ResultCallback<Status>() {
                                                                                @Override
                                                                                public void onResult(
                                                                                        Status status) {
                                                                                    //also revoke google access
                                                                                    Auth.GoogleSignInApi
                                                                                            .revokeAccess(
                                                                                                    googleApiClient)
                                                                                            .setResultCallback(
                                                                                                    new ResultCallback<Status>() {
                                                                                                        @Override
                                                                                                        public void onResult(
                                                                                                                Status status) {
                                                                                                            progressDialog
                                                                                                                    .dismiss();
                                                                                                            TelepathyBaseActivity currentActivity = (TelepathyBaseActivity) TApplication.mCurrentActivityInApplication;
                                                                                                            if (currentActivity != null) {
                                                                                                                Intent intent = new Intent(
                                                                                                                        TApplication.applicationContext,
                                                                                                                        SignInActivity.class);
                                                                                                                intent.setFlags(
                                                                                                                        Intent.FLAG_ACTIVITY_CLEAR_TASK
                                                                                                                                | Intent.FLAG_ACTIVITY_NEW_TASK);
                                                                                                                currentActivity
                                                                                                                        .startActivity(
                                                                                                                                intent);
                                                                                                                currentActivity
                                                                                                                        .setAnimationOnStart();
                                                                                                                currentActivity
                                                                                                                        .finish();
                                                                                                            }
                                                                                                        }
                                                                                                    });
                                                                                }
                                                                            });
                                                        }

                                                        @Override
                                                        public void onConnectionSuspended(int i) {
                                                            //do nothing
                                                        }
                                                    });
                                        }
                                    }

                                    @Override
                                    public void failure(RetrofitError error) {
                                        progressDialog.dismiss();
                                        if (getActivity() != null && isAdded()) {
                                            CommonFeedBack commonFeedBack = new CommonFeedBack(
                                                    getActivity().findViewById(android.R.id.content),
                                                    getActivity());
                                            commonFeedBack.checkCommonErrorAndBackUnCommonOne(error);
                                        }
                                    }
                                });
                            }
                        });
                confirmAccountDeleteDialog.show();
            } catch (Exception ex) {
                AndroidUtilities.processApplicationError(ex, true);
                if (isAdded() && getActivity() != null) {
                    Snackbar.make(getActivity().findViewById(android.R.id.content),
                            getString(R.string.re_action_internal_app_error), Snackbar.LENGTH_LONG).show();
                }
            }
        }
    });
    builder.setView(customLayout);
    return builder.create();
}

From source file:net.olejon.mdapp.BarcodeScannerActivity.java

@Override
public void handleResult(Result result) {
    mTools.showToast(getString(R.string.barcode_scanner_wait), 0);

    String barcode = result.getText();

    RequestQueue requestQueue = Volley.newRequestQueue(mContext);

    JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET,
            getString(R.string.project_website_uri) + "api/1/barcode/?search=" + barcode,
            new Response.Listener<JSONObject>() {
                @Override/* w  w  w .  ja va 2  s  . c  o  m*/
                public void onResponse(JSONObject response) {
                    try {
                        String medicationName = response.getString("name");

                        if (medicationName.equals("")) {
                            mTools.showToast(getString(R.string.barcode_scanner_no_results), 1);

                            finish();
                        } else {
                            SQLiteDatabase sqLiteDatabase = new SlDataSQLiteHelper(mContext)
                                    .getReadableDatabase();

                            String[] queryColumns = { SlDataSQLiteHelper.MEDICATIONS_COLUMN_ID };
                            Cursor cursor = sqLiteDatabase.query(SlDataSQLiteHelper.TABLE_MEDICATIONS,
                                    queryColumns,
                                    SlDataSQLiteHelper.MEDICATIONS_COLUMN_NAME + " LIKE "
                                            + mTools.sqe("%" + medicationName + "%") + " COLLATE NOCASE",
                                    null, null, null, null);

                            if (cursor.moveToFirst()) {
                                long id = cursor.getLong(
                                        cursor.getColumnIndexOrThrow(SlDataSQLiteHelper.MEDICATIONS_COLUMN_ID));

                                Intent intent = new Intent(mContext, MedicationActivity.class);

                                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                                    if (mTools.getDefaultSharedPreferencesBoolean(
                                            "MEDICATION_MULTIPLE_DOCUMENTS"))
                                        intent.setFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK
                                                | Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
                                }

                                intent.putExtra("id", id);
                                startActivity(intent);
                            }

                            cursor.close();
                            sqLiteDatabase.close();

                            finish();
                        }
                    } catch (Exception e) {
                        mTools.showToast(getString(R.string.barcode_scanner_no_results), 1);

                        Log.e("BarcodeScannerActivity", Log.getStackTraceString(e));

                        finish();
                    }
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Log.e("FelleskatalogenService", error.toString());
                }
            });

    jsonObjectRequest.setRetryPolicy(new DefaultRetryPolicy(10000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

    requestQueue.add(jsonObjectRequest);
}

From source file:com.github.michalbednarski.intentslab.StartActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_start, menu);
    // TODO: move to menu resource
    menu.add("Proxy log (experimental)").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override//from  w w  w.  ja  v a  2  s.c  o  m
        public boolean onMenuItemClick(MenuItem item) {
            startActivity(new Intent(StartActivity.this, LogViewerActivity.class));
            return true;
        }
    });
    menu.add("RunAs local (experimental)").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            (new Thread() {
                @Override
                public void run() {
                    RemoteEntryPoint
                            .main(new String[] { new ComponentName(StartActivity.this, RunAsInitReceiver.class)
                                    .flattenToShortString() });
                }
            }).start();
            return true;
        }
    });
    menu.add("Activity Monitor (experimental)")
            .setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    startActivity(new Intent(StartActivity.this, ActivityMonitorActivity.class));
                    return true;
                }
            });
    menu.add("Current objects (experimental)")
            .setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    startActivity(new Intent(StartActivity.this, ClipboardActivity.class));
                    return true;
                }
            });
    menu.add("Another instance (experimental)")
            .setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    startActivity(new Intent(StartActivity.this, StartActivityMultitask.class)
                            .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK)
                            .setAction("mi" + new Random().nextLong()));
                    return true;
                }
            });
    return true;
}

From source file:net.olejon.mdapp.ManufacturerActivity.java

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

    // Intent/* w  ww .j a  v a  2s .  c  o m*/
    final Intent intent = getIntent();

    final long manufacturerId = intent.getLongExtra("id", 0);

    // Layout
    setContentView(R.layout.activity_manufacturer);

    // Get manufacturer
    mSqLiteDatabase = new SlDataSQLiteHelper(mContext).getReadableDatabase();

    String[] manufacturersQueryColumns = { SlDataSQLiteHelper.MANUFACTURERS_COLUMN_NAME };
    mCursor = mSqLiteDatabase.query(SlDataSQLiteHelper.TABLE_MANUFACTURERS, manufacturersQueryColumns,
            SlDataSQLiteHelper.MANUFACTURERS_COLUMN_ID + " = " + manufacturerId, null, null, null, null);

    if (mCursor.moveToFirst()) {
        manufacturerName = mCursor
                .getString(mCursor.getColumnIndexOrThrow(SlDataSQLiteHelper.MANUFACTURERS_COLUMN_NAME));

        String[] medicationsQueryColumns = { SlDataSQLiteHelper.MEDICATIONS_COLUMN_ID,
                SlDataSQLiteHelper.MEDICATIONS_COLUMN_NAME, SlDataSQLiteHelper.MEDICATIONS_COLUMN_SUBSTANCE };
        mCursor = mSqLiteDatabase.query(SlDataSQLiteHelper.TABLE_MEDICATIONS, medicationsQueryColumns,
                SlDataSQLiteHelper.MEDICATIONS_COLUMN_MANUFACTURER + " = " + mTools.sqe(manufacturerName), null,
                null, null, SlDataSQLiteHelper.MEDICATIONS_COLUMN_NAME + " COLLATE NOCASE");

        String[] fromColumns = { SlDataSQLiteHelper.MEDICATIONS_COLUMN_NAME,
                SlDataSQLiteHelper.MEDICATIONS_COLUMN_SUBSTANCE };
        int[] toViews = { R.id.manufacturer_list_item_name, R.id.manufacturer_list_item_substance };

        SimpleCursorAdapter simpleCursorAdapter = new SimpleCursorAdapter(mContext,
                R.layout.activity_manufacturer_list_item, mCursor, fromColumns, toViews, 0);

        // Toolbar
        final Toolbar toolbar = (Toolbar) findViewById(R.id.manufacturer_toolbar);
        toolbar.setTitle(manufacturerName);

        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        // Medications count
        int medicationsCount = mCursor.getCount();

        String medications = (medicationsCount == 1) ? getString(R.string.manufacturer_medication)
                : getString(R.string.manufacturer_medications);

        TextView medicationsCountTextView = (TextView) findViewById(R.id.manufacturer_medications_count);
        medicationsCountTextView.setText(medicationsCount + " " + medications);

        // List
        ListView listView = (ListView) findViewById(R.id.manufacturer_list);
        listView.setAdapter(simpleCursorAdapter);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                if (mCursor.moveToPosition(i)) {
                    long id = mCursor
                            .getLong(mCursor.getColumnIndexOrThrow(SlDataSQLiteHelper.MEDICATIONS_COLUMN_ID));

                    Intent intent = new Intent(mContext, MedicationActivity.class);

                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                        if (mTools.getDefaultSharedPreferencesBoolean("MEDICATION_MULTIPLE_DOCUMENTS"))
                            intent.setFlags(
                                    Intent.FLAG_ACTIVITY_MULTIPLE_TASK | Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
                    }

                    intent.putExtra("id", id);
                    startActivity(intent);
                }
            }
        });
    }
}

From source file:ru.gelin.android.weather.notification.skin.impl.BaseWeatherNotificationReceiver.java

/**
 *  Returns the pending intent called on click on notification.
 *  This intent starts the weather info activity.
 *///from  w w  w. j a  va 2  s .com
protected PendingIntent getContentIntent(Context context) {
    Intent intent = new Intent();
    intent.setComponent(getWeatherInfoActivityComponentName());
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
    intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    return PendingIntent.getActivity(context, 0, intent, 0);
}