Example usage for android.content Intent FLAG_ACTIVITY_CLEAR_TASK

List of usage examples for android.content Intent FLAG_ACTIVITY_CLEAR_TASK

Introduction

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

Prototype

int FLAG_ACTIVITY_CLEAR_TASK

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

Click Source Link

Document

If set in an Intent passed to Context#startActivity Context.startActivity() , this flag will cause any existing task that would be associated with the activity to be cleared before the activity is started.

Usage

From source file:com.remedy.glass.RemedyService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    String username = intent.getStringExtra(EXTRA_USERNAME);
    if (username != null) {
        Context ctx = getApplicationContext();
        mPhone = new RemedyPhone(ctx, username);
        mPoller = new MessagePoller(ctx, username);
    } else {//w  w  w  .jav a2s  .  com
        Intent loginIntent = new Intent(this, LoginActivity.class);
        loginIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        getApplication().startActivity(loginIntent);
    }

    return START_STICKY;
}

From source file:com.mokee.setupwizard.SetupWizardActivity.java

private void finishSetup() {
    Settings.Global.putInt(getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 1);
    Settings.Secure.putInt(getContentResolver(), Settings.Secure.USER_SETUP_COMPLETE, 1);
    enableStatusBar();/*from   w w w  . j a  v  a2s  .  com*/
    Intent intent = new Intent("android.intent.action.MAIN");
    intent.addCategory("android.intent.category.HOME");
    disableSetupWizards(intent);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | intent.getFlags());
    startActivity(intent);
    finish();
}

From source file:com.paranoid.lukemovement.halolauncher.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_exit:
        finish();/*from w  w w  .  jav  a  2 s . co  m*/
        break;
    case R.id.action_settings:
        startActivity(new Intent(this, Settings.class).addFlags(0x00002000 | Intent.FLAG_ACTIVITY_CLEAR_TASK));
        finish();
        break;
    }
    return true;
}

From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.webview.GBWebClient.java

@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
    Uri parsedUri = Uri.parse(url);/*from  w ww .jav a  2s.co  m*/

    if (parsedUri.getScheme().startsWith("http")) {
        Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        GBApplication.getContext().startActivity(i);
    } else if (parsedUri.getScheme().startsWith("pebblejs")) {
        url = url.replaceFirst("^pebblejs://close#",
                "file:///android_asset/app_config/configure.html?config=true&json=");
        view.loadUrl(url);
    } else if (parsedUri.getScheme().equals("data")) { //clay
        view.loadUrl(url);
    } else {
        LOG.debug("WEBVIEW Ignoring unhandled scheme: " + parsedUri.getScheme());
    }

    return true;
}

From source file:emu.project64.settings.BaseSettingsFragment.java

@Override
public boolean onPreferenceTreeClick(Preference preference) {
    if (preference.getKey().equals("settings_input")) {
        loadFragment(new InputFragment());
    } else if (preference.getKey().equals("settings_touch_screen")) {
        loadFragment(new TouchScreenFragment());
    } else if (preference.getKey().equals("settings_gamepad_screen")) {
        final AppCompatActivity activity = (AppCompatActivity) getActivity();
        Intent intent = new Intent(activity, ControllerProfileActivity.class);
        activity.startActivity(intent);/*from   www . j a v  a2 s  . com*/
    } else if (preference.getKey().equals("settings_video")) {
        loadFragment(new VideoFragment());
    } else if (preference.getKey().equals("settings_game_list")) {
        loadFragment(new GameListFragment());
    } else if (preference.getKey().equals("settings_audio")) {
        loadFragment(new AudioFragment());
    } else if (preference.getKey().equals("settings_advanced")) {
        loadFragment(new AdvancedFragment());
    } else if (preference.getKey().equals("logging_core")) {
        loadFragment(new LoggingProject64Core());
    } else if (preference.getKey().equals("logging_audio")) {
        loadFragment(new LoggingAudio());
    } else if (preference.getKey().equals("settings_reset")) {
        DialogInterface.OnClickListener internalListener = new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (which == DialogInterface.BUTTON_POSITIVE) {
                    NativeExports.ResetApplicationSettings();
                    SplashActivity.Reset();
                    Intent SplashIntent = new Intent(getActivity(), SplashActivity.class);
                    SplashIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                    startActivity(SplashIntent);
                }
            }
        };

        String title = getString(R.string.settings_reset_title);
        String message = getString(R.string.settings_reset_message);
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()).setTitle(title).setMessage(message)
                .setCancelable(false).setNegativeButton(getString(android.R.string.cancel), internalListener)
                .setPositiveButton(getString(android.R.string.ok), internalListener);
        builder.create().show();
    } else {
        return super.onPreferenceTreeClick(preference);
    }
    return true;
}

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);//  www .j av  a  2  s. c  o 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: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  ava  2 s .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.asksven.betterbatterystats.PackageFragmentActivity.java

public static void showAppOps(Context context, String packageName) {

    Intent intent = null;/*from  ww w. j a  v a 2s . c  o m*/
    // JB
    if (Build.VERSION.SDK_INT == 18) {
        intent = new Intent("android.settings.APP_OPS_SETTINGS");
        Uri uri = Uri.fromParts(SCHEME, packageName, null);
    } else if (Build.VERSION.SDK_INT >= 19) {
        // @see http://brightechno.com/blog/archives/211
        intent = new Intent();
        intent.setClassName("com.android.settings", "com.android.settings.Settings");
        intent.setAction(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_DEFAULT);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK
                | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
        intent.putExtra(":android:show_fragment", "com.android.settings.applications.AppOpsSummary");
    }

    if (intent != null) {
        try {
            context.startActivity(intent);
        } catch (ActivityNotFoundException e) {
            Toast.makeText(context, context.getString(R.string.message_no_appops), Toast.LENGTH_SHORT).show();
        }

    }
}

From source file:org.wso2.cdm.agent.services.PolicyTester.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public PolicyTester(Context context, JSONArray recJArray, int type, String msgID) {
    this.context = context;
    devicePolicyManager = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
    appList = new ApplicationManager(context);
    deviceInfo = new DeviceInfo(context);
    deviceState = new PhoneState(context);

    if (type == POLICY_MONITOR_TYPE_NO_ENFORCE_RETURN) {
        IS_ENFORCE = false;/*from w w w .j  av  a  2 s . c o  m*/
    } else if (type == POLICY_MONITOR_TYPE_NO_ENFORCE_MESSAGE_RETURN) {
        IS_ENFORCE = false;
    } else if (type == POLICY_MONITOR_TYPE_ENFORCE_RETURN) {
        IS_ENFORCE = true;
    } else {
        IS_ENFORCE = false;
        type = POLICY_MONITOR_TYPE_NO_ENFORCE_MESSAGE_RETURN;
    }

    SharedPreferences mainPref = context.getSharedPreferences("com.mdm", Context.MODE_PRIVATE);
    policy = mainPref.getString("policy", "");

    try {
        JSONArray jArray = null;
        if (recJArray != null) {
            jArray = recJArray;
        } else {
            jArray = new JSONArray(policy);
        }
        Log.e("POLICY ARAY : ", jArray.toString());
        for (int i = 0; i < jArray.length(); i++) {
            JSONObject policyObj = (JSONObject) jArray.getJSONObject(i);
            if (policyObj.getString("data") != null && policyObj.getString("data") != "") {
                testPolicy(policyObj.getString("code"), policyObj.getString("data"));
            }
        }

        JSONObject rootObj = new JSONObject();
        try {
            if (deviceInfo.isRooted()) {
                rootObj.put("status", false);
            } else {
                rootObj.put("status", true);
            }
            rootObj.put("code", "notrooted");
            finalArray.put(rootObj);
        } catch (JSONException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        Log.e("MONITOR POLICY : ", policy);
        Log.e("MONITOR USER MESSAGE : ", usermessage);
        //Display an alert to the user about policy violation
        if (policy != null && policy != "") {
            if (usermessage != null && usermessage != ""
                    && type == POLICY_MONITOR_TYPE_NO_ENFORCE_MESSAGE_RETURN) {
                Intent intent = new Intent(context, AlertActivity.class);
                intent.putExtra("message", usermessage);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP
                        | Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(intent);
            }
        }

        returnJSON.put("code", CommonUtilities.OPERATION_POLICY_MONITOR);
        returnJSON.put("data", finalArray);

        Map<String, String> params = new HashMap<String, String>();
        params.put("code", CommonUtilities.OPERATION_POLICY_MONITOR);
        params.put("msgID", msgID);
        params.put("status", "200");
        params.put("data", finalArray.toString());

        //ServerUtilities.pushData(params, context);
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

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/*from   w  w w .  j  a  v  a  2  s  .  co  m*/
                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);

}