Example usage for android.content Intent FLAG_ACTIVITY_NEW_TASK

List of usage examples for android.content Intent FLAG_ACTIVITY_NEW_TASK

Introduction

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

Prototype

int FLAG_ACTIVITY_NEW_TASK

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

Click Source Link

Document

If set, this activity will become the start of a new task on this history stack.

Usage

From source file:com.polyvi.xface.extension.XAppExt.java

@Override
public XExtensionResult exec(String action, JSONArray args, XCallbackContext callbackCtx) throws JSONException {
    XExtensionResult.Status status = XExtensionResult.Status.OK;
    String result = "";
    try {/*from  w  w  w  . j  av  a 2  s  .c  o  m*/
        if (action.equals(COMMAND_EXITAPP)) {
            exitApp();
        } else if (COMMAND_OPEN_URL.equals(action)) {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            String url = args.getString(0);
            Uri uri = getUrlFromPath(mWebContext, url);
            if (null == uri) {
                status = XExtensionResult.Status.ERROR;
                result = "file not exist";
                return new XExtensionResult(status, result);
            }
            setDirPermisionUntilWorkspace(mWebContext, uri);
            setIntentByUri(intent, uri);
            getContext().startActivity(intent);
        } else if (COMMAND_INSTALL.equals(action)) {
            XPathResolver pathResolver = new XPathResolver(args.getString(0), mWebContext.getWorkSpace());
            install(pathResolver.resolve(), callbackCtx);
            return new XExtensionResult(XExtensionResult.Status.NO_RESULT);
        } else if (COMMAND_START_SYSTEM_COMPONENT.equals(action)) {
            if (!startSystemComponent(args.getInt(0))) {
                status = XExtensionResult.Status.ERROR;
                result = "Unsupported component:: " + args.getString(0);
            }
        } else if (COMMAND_SET_WIFI_SLEEP_POLICY.equals(action)) {
            if (!setWifiSleepPolicy(args.getString(0))) {
                status = XExtensionResult.Status.ERROR;
                result = "set wifi sleep policy error";
            }
        } else if (COMMAND_LOAD_URL.equals(action)) {
            boolean openExternal = Boolean.valueOf(args.getString(1));
            boolean clearHistory = Boolean.valueOf(args.getString(2));
            loadUrl(args.getString(0), openExternal, clearHistory, mWebContext);
        } else if (COMMAND_BACK_HISTORY.equals(action)) {
            backHistory(mWebContext);
        } else if (COMMAND_CLEAR_HISTORY.equals(action)) {
            clearHistory(mWebContext);
        } else if (COMMAND_CLEAR_CACHE.equalsIgnoreCase(action)) {
            clearCache(mWebContext);
        } else if (COMMAND_START_NATIVE_APP.equalsIgnoreCase(action)) {
            if (!XAppUtils.startNativeApp(mExtensionContext.getSystemContext().getContext(), args.getString(0),
                    XConstant.TAG_APP_START_PARAMS, args.getString(1))) {
                status = XExtensionResult.Status.ERROR;
            }
        } else if (COMMAND_IS_NATIVE_APP_INSTALLED.equals(action)) {
            boolean installResult = false;
            if (isAppInstalled(args.getString(0))) {
                installResult = true;
            }
            return new XExtensionResult(status, installResult);
        } else if (COMMAND_TEL_LINK_ENABLE.equals(action)) {
            XConfiguration.getInstance().setTelLinkEnabled(args.optBoolean(0, true));
        } else if (COMMAND_QUERY_INSTALLED_NATIVEAPP.equals(action)) {
            return new XExtensionResult(status, queryInstalledNativeApp(args.getString(0)));
        } else if (COMMAND_UNINSTALL_NATIVEAPP.equals(action)) {
            uninstallNativeApp(args.getString(0), callbackCtx);
            return new XExtensionResult(XExtensionResult.Status.NO_RESULT);
        } else {
            status = XExtensionResult.Status.INVALID_ACTION;
            result = "Unsupported Operation: " + action;
        }
        return new XExtensionResult(status, result);
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
        return new XExtensionResult(XExtensionResult.Status.ERROR);
    }
}

From source file:id.zelory.tanipedia.activity.CuacaActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_cuaca);
    toolbar = (Toolbar) findViewById(R.id.anim_toolbar);
    setSupportActionBar(toolbar);/*from  w ww . j a v a  2  s.  co m*/
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    collapsingToolbar = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);

    animation = AnimationUtils.loadAnimation(this, R.anim.simple_grow);

    drawerLayout = (DrawerLayout) findViewById(R.id.nav_drawer);
    setUpNavDrawer();
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    TextView nama = (TextView) navigationView.findViewById(R.id.nama);
    nama.setText(PrefUtils.ambilString(this, "nama"));
    TextView email = (TextView) navigationView.findViewById(R.id.email);
    email.setText(PrefUtils.ambilString(this, "email"));
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            menuItem.setChecked(true);
            drawerLayout.closeDrawers();
            Intent intent;
            switch (menuItem.getItemId()) {
            case R.id.cuaca:
                return true;
            case R.id.berita:
                intent = new Intent(CuacaActivity.this, BeritaActivity.class);
                break;
            case R.id.tanya:
                intent = new Intent(CuacaActivity.this, TanyaActivity.class);
                break;
            case R.id.harga:
                intent = new Intent(CuacaActivity.this, KomoditasActivity.class);
                break;
            case R.id.logout:
                PrefUtils.simpanString(CuacaActivity.this, "nama", null);
                intent = new Intent(CuacaActivity.this, LoginActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                startActivity(intent);
                return true;
            case R.id.tentang:
                intent = new Intent(CuacaActivity.this, TentangActivity.class);
                startActivity(intent);
                return true;
            default:
                return true;
            }
            startActivity(intent);
            finish();
            return true;
        }
    });

    recyclerView = (RecyclerView) findViewById(R.id.scrollableview);
    recyclerView.setHasFixedSize(true);
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
    recyclerView.setLayoutManager(linearLayoutManager);

    fabButton = (FabButton) findViewById(R.id.determinate);
    fabButton.showProgress(true);
    fabButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            fabButton.showProgress(true);
            new DownloadData().execute();
        }
    });

    cuacaText = (TextView) findViewById(R.id.cuaca);
    suhu = (TextView) findViewById(R.id.suhu);
    minmax = (TextView) findViewById(R.id.minmax);
    iconCuaca = (ImageView) findViewById(R.id.icon_cuaca);
    kegiatan = (TextView) findViewById(R.id.kegiatan);
    background = (LinearLayout) findViewById(R.id.background);

    cuacaText.setVisibility(View.GONE);
    suhu.setVisibility(View.GONE);
    minmax.setVisibility(View.GONE);
    iconCuaca.setVisibility(View.GONE);
    kegiatan.setVisibility(View.GONE);

    if (checkPlayServices()) {
        buildGoogleApiClient();
    }

}

From source file:com.partner.common.updater.ApkDownloadUtil.java

public static void installBundledApps(File file) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PartnerApplication.getInstance().startActivity(intent);
}

From source file:de.madvertise.android.sdk.MadvertiseMraidView.java

public MadvertiseMraidView(Context context) {
    super(context);
    setVerticalScrollBarEnabled(false);/*from   w w w  .  j a va 2 s .com*/
    setHorizontalScrollBarEnabled(false);
    setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
    setBackgroundColor(Color.TRANSPARENT);
    WebSettings settings = getSettings();
    settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
    settings.setJavaScriptEnabled(true);
    //settings.setPluginsEnabled(true);

    // Initialize the default expand properties.
    DisplayMetrics metrics = getContext().getResources().getDisplayMetrics();
    mExpandProperties = new ExpandProperties(metrics.widthPixels, metrics.heightPixels);
    MadvertiseUtil.logMessage(null, Log.INFO,
            "Setting default expandProperties : " + mExpandProperties.toJson().toString());

    // This bridge stays available until this view is destroyed, hence no
    // reloading when displaying new ads is necessary.
    addJavascriptInterface(mBridge, "mraid_bridge");

    setWebViewClient(new WebViewClient() {
        private boolean mError = false;

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, final String url) {
            post(new Runnable() {
                @Override
                public void run() {
                    if (mListener != null) {
                        mListener.onAdClicked();
                    }
                    final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url),
                            getContext().getApplicationContext(), MadvertiseActivity.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    getContext().startActivity(intent);
                }
            });
            return true;
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            if (!url.endsWith("mraid.js") && !mError) {
                MadvertiseUtil.logMessage(null, Log.DEBUG, "Setting mraid to default");
                checkReady();

                // Close button in default size for interstitial ads
                if (mPlacementType == MadvertiseUtil.PLACEMENT_TYPE_INTERSTITIAL) {
                    mCloseButton = addCloseButtonToViewGroup(((ViewGroup) getParent()));
                    mCloseButton.setImageResource(android.R.drawable.ic_menu_close_clear_cancel);
                }
            }
        }

        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            super.onReceivedError(view, errorCode, description, failingUrl);
            mError = true;
        }
    });

    // Comment this in to enable video tag-capability.
    this.setWebChromeClient(new WebChromeClient() {

        @Override
        public void onShowCustomView(View view, CustomViewCallback callback) {
            MadvertiseUtil.logMessage(null, Log.INFO, "showing VideoView");
            super.onShowCustomView(view, callback);
            if (view instanceof FrameLayout) {
                FrameLayout frame = (FrameLayout) view;
                if (frame.getFocusedChild() instanceof VideoView) {
                    mVideo = (VideoView) ((FrameLayout) view).getFocusedChild();
                    frame.removeView(mVideo);
                    ((ViewGroup) getParent()).addView(mVideo);

                    // Will also be called onError
                    mVideo.setOnCompletionListener(new OnCompletionListener() {

                        @Override
                        public void onCompletion(MediaPlayer player) {
                            player.stop();
                        }
                    });

                    mVideo.setOnErrorListener(new OnErrorListener() {

                        @Override
                        public boolean onError(MediaPlayer mp, int what, int extra) {
                            MadvertiseUtil.logMessage(null, Log.WARN, "Error while playing video");

                            if (mListener != null) {
                                mListener.onError(new IOException("Error while playing video"));
                            }

                            // We return false in order to call
                            // onCompletion()
                            return false;
                        }
                    });

                    mVideo.start();
                }
            }
        }

        @Override
        public void onHideCustomView() {
            if (mVideo != null) {
                ((ViewGroup) getParent()).removeView(mVideo);
                if (mVideo.isPlaying()) {
                    mVideo.stopPlayback();
                }
            }
        }
    });
}

From source file:id.zelory.tanipedia.activity.TanyaActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_tanya);
    toolbar = (Toolbar) findViewById(R.id.anim_toolbar);
    setSupportActionBar(toolbar);/*from   w  w  w .j a v a  2s  .c  om*/
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
    collapsingToolbar.setTitle("Tanya Tani");

    animation = AnimationUtils.loadAnimation(this, R.anim.simple_grow);
    fabMargin = getResources().getDimensionPixelSize(R.dimen.fab_margin);

    drawerLayout = (DrawerLayout) findViewById(R.id.nav_drawer);
    setUpNavDrawer();
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.getMenu().getItem(2).setChecked(true);
    TextView nama = (TextView) navigationView.findViewById(R.id.nama);
    nama.setText(PrefUtils.ambilString(this, "nama"));
    TextView email = (TextView) navigationView.findViewById(R.id.email);
    email.setText(PrefUtils.ambilString(this, "email"));
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            menuItem.setChecked(true);
            drawerLayout.closeDrawers();
            Intent intent;
            switch (menuItem.getItemId()) {
            case R.id.cuaca:
                intent = new Intent(TanyaActivity.this, CuacaActivity.class);
                break;
            case R.id.berita:
                intent = new Intent(TanyaActivity.this, BeritaActivity.class);
                break;
            case R.id.tanya:
                return true;
            case R.id.harga:
                intent = new Intent(TanyaActivity.this, KomoditasActivity.class);
                break;
            case R.id.logout:
                PrefUtils.simpanString(TanyaActivity.this, "nama", null);
                intent = new Intent(TanyaActivity.this, LoginActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                startActivity(intent);
                return true;
            case R.id.tentang:
                intent = new Intent(TanyaActivity.this, TentangActivity.class);
                startActivity(intent);
                return true;
            default:
                return true;
            }
            startActivity(intent);
            finish();
            return true;
        }
    });

    recyclerView = (RecyclerView) findViewById(R.id.scrollableview);
    recyclerView.setHasFixedSize(true);
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
    recyclerView.setLayoutManager(linearLayoutManager);
    recyclerView.addOnScrollListener(new MyRecyclerScroll() {
        @Override
        public void show() {
            fab.animate().translationY(0).setInterpolator(new DecelerateInterpolator(2)).start();
        }

        @Override
        public void hide() {
            fab.animate().translationY(fab.getHeight() + fabMargin)
                    .setInterpolator(new AccelerateInterpolator(2)).start();
        }
    });

    tanyaGambar = (ImageView) findViewById(R.id.tanya_gambar);
    tanyaGambar.setVisibility(View.GONE);
    fab = (FrameLayout) findViewById(R.id.myfab_main);
    fab.setVisibility(View.GONE);
    fabBtn = (ImageButton) findViewById(R.id.myfab_main_btn);
    View fabShadow = findViewById(R.id.myfab_shadow);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        fabShadow.setVisibility(View.GONE);
        fabBtn.setBackground(getDrawable(R.drawable.ripple_accent));
    }

    fabBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            new MaterialDialog.Builder(TanyaActivity.this).title("TaniPedia").content("Kirim Pertanyaan")
                    .inputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_CLASS_TEXT)
                    .input("Ketik pertanyaan anda disini!", null, false, new MaterialDialog.InputCallback() {
                        @Override
                        public void onInput(MaterialDialog dialog, CharSequence input) {
                            try {
                                pertanyaan = URLEncoder.encode(input.toString(), "UTF-8");
                                new KirimSoal().execute();
                            } catch (UnsupportedEncodingException e) {
                                Snackbar.make(fabBtn, "Terjadi kesalahan, silahkan coba lagi!",
                                        Snackbar.LENGTH_LONG).show();
                                e.printStackTrace();
                            }
                        }
                    }).positiveColorRes(R.color.primary_dark).positiveText("Kirim")
                    .cancelListener(new DialogInterface.OnCancelListener() {
                        @Override
                        public void onCancel(DialogInterface dialog) {

                        }
                    }).negativeColorRes(R.color.primary_dark).negativeText("Batal").show();
        }
    });

    fabButton = (FabButton) findViewById(R.id.determinate);
    fabButton.showProgress(true);
    new DownloadData().execute();
    fabButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            fabButton.showProgress(true);
            new DownloadData().execute();
        }
    });
}

From source file:com.stroke.academy.common.updater.ApkDownloadUtil.java

public static void installBundledApps(File file) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    AcademyApplication.getInstance().startActivity(intent);
}

From source file:com.phonegap.cordova.FileOpener.java

private void openFile(String url, String type) throws IOException {
    // Create URI
    Uri uri = Uri.parse(url);/*from   w  w w.j a va 2 s .  c o m*/

    Intent intent = null;
    Log.v("FileOpener", "Type: " + type);

    if (type.equals("pdfshare")) {
        intent = new Intent(Intent.ACTION_SEND, Uri.parse("mailto:"));
        // intent.setDataAndType(uri, "application/pdf");
        intent.setType("application/pdf");
        intent.putExtra(Intent.EXTRA_SUBJECT, "AMR Report");
        intent.putExtra(Intent.EXTRA_TEXT, "");
        intent.putExtra(Intent.EXTRA_STREAM, uri);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    } else if (url.contains(".pdf")) {
        // PDF file
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "application/pdf");
    } else if (url.contains(".ppt") || url.contains(".pptx")) {
        // Powerpoint file
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "application/vnd.ms-powerpoint");
    } else if (url.contains(".xls") || url.contains(".xlsx")) {
        // Excel file
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "application/vnd.ms-excel");
    } else if (url.contains(".rtf")) {
        // RTF file
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "application/rtf");
    } else if (url.contains(".wav")) {
        // WAV audio file
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "audio/x-wav");
    } else if (url.contains(".gif")) {
        // GIF file
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "image/gif");
    } else if (url.contains(".jpg") || url.contains(".jpeg")) {
        // JPG file
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "image/jpeg");
    } else if (url.contains(".png")) {
        // PNG file
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "image/png");
    } else if (url.contains(".txt")) {
        // Text file
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "text/plain");
    } else if (url.contains(".mpg") || url.contains(".mpeg") || url.contains(".mpe") || url.contains(".mp4")
            || url.contains(".avi")) {
        // Video files
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "video/*");
    } else if (url.contains(".doc") || url.contains(".docx")) {
        // Word document
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "application/msword");
    }

    //if you want you can also define the intent type for any other file

    //additionally use else clause below, to manage other unknown extensions
    //in this case, Android will show all applications installed on the device
    //so you can choose which application to use

    else if (type.equals("none") || type.equals("*/*")) {
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "*/*");
    } else {
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setAction(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, type);
    }

    //TRY Catch error
    try {
        this.cordova.getActivity().startActivity(intent);
    } catch (ActivityNotFoundException e) {
        intent.setData(uri);
        this.cordova.getActivity().startActivity(intent);
    }
}

From source file:com.example.administrator.myapplication2._5_Group._5_Group.LeftFragment.java

public void outGroup() {

    AsyncHttpClient client1 = new AsyncHttpClient();
    client1.get("http://14.63.219.140:8080/han5/webresources/han5.grouping/deleteGrouping/" + id,
            new JsonHttpResponseHandler() {
                @Override//  w ww.j a  va 2  s. c om
                public void onStart() {
                    Log.i("boogil1", "outGroup receive json data start! ");
                }

                @Override
                public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                    Log.i("boogil1", "outGroup success! ");
                }

                @Override
                public void onFailure(int statusCode, Header[] headers, String responseString,
                        Throwable throwable) {
                    Log.i("boogil1", "outGroup fail!");
                }
            });

    AsyncHttpClient client2 = new AsyncHttpClient();
    client2.get("http://14.63.219.140:8080/han5/webresources/han5.nowgps/deleteNowgps/" + id,
            new JsonHttpResponseHandler() {
                @Override
                public void onStart() {
                    Log.i("boogil1", "outGroup2 receive json data start! ");
                }

                @Override
                public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                    Log.i("boogil1", "outGroup2 success! ");
                }

                @Override
                public void onFailure(int statusCode, Header[] headers, String responseString,
                        Throwable throwable) {
                    Log.i("boogil1", "outGroup2 fail!");
                }
            });

    //Set Class to Top of App and no history
    Intent launchNextActivity;
    launchNextActivity = new Intent(getActivity(), Main.class);
    launchNextActivity.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    launchNextActivity.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    launchNextActivity.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
    startActivity(launchNextActivity);

}

From source file:com.avanade.C2DMReceiver.java

@Override
protected void onMessage(Context context, Intent intent) {
    int flag = 0;
    Log.w("C2DMReceiver", intent.getStringExtra("Count"));
    String count = intent.getStringExtra("Count");
    ActivityManager activityManager = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
    List<RunningAppProcessInfo> procInfos = activityManager.getRunningAppProcesses();
    for (int i = 0; i < procInfos.size(); i++) {
        if (procInfos.get(i).processName.equals("com.avanade")) {
            if (count.startsWith("com.avanade")) {
                count = getIntFromEndOfString(count);
                numberNoti = count;//  ww w.j  a va  2  s  .  c o  m
                flag = 1;
                break;
            }
        }
    }
    if (flag == 1) {
        Intent pushUpdateIntent = new Intent(getBaseContext(), PushUpdate.class);
        pushUpdateIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        //pushUpdateIntent.putExtra("unregister", true);
        getApplication().startActivity(pushUpdateIntent);
        flag = 0;
    } else {
        //         System.out.println(" the app is not runnning......do something");
        //Toast.makeText(getApplicationContext(), "Notification Received", Toast.LENGTH_SHORT).show();
    }
}

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.AppReferenceObj.java

@Override
public void handleDirectMessage(Context context, Contact from, JSONObject obj) {
    String packageName = obj.optString(PACKAGE_NAME);
    String arg = obj.optString(ARG);
    Intent launch = new Intent();
    launch.setAction(Intent.ACTION_MAIN);
    launch.addCategory(Intent.CATEGORY_LAUNCHER);
    launch.putExtra(AppState.EXTRA_APPLICATION_ARGUMENT, arg);
    launch.putExtra("creator", false);
    launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    launch.setPackage(packageName);/*from   w  ww .j a v  a  2  s  . c  o  m*/
    final PackageManager mgr = context.getPackageManager();
    List<ResolveInfo> resolved = mgr.queryIntentActivities(launch, 0);
    if (resolved == null || resolved.size() == 0) {
        Toast.makeText(context, "Could not find application to handle invite", Toast.LENGTH_SHORT).show();
        return;
    }
    ActivityInfo info = resolved.get(0).activityInfo;
    launch.setComponent(new ComponentName(info.packageName, info.name));
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, launch,
            PendingIntent.FLAG_CANCEL_CURRENT);

    (new PresenceAwareNotify(context)).notify("New Invitation", "Invitation received from " + from.name,
            "Click to launch application.", contentIntent);
}