當前位置: 首頁>>代碼示例>>Java>>正文


Java NavUtils.shouldUpRecreateTask方法代碼示例

本文整理匯總了Java中android.support.v4.app.NavUtils.shouldUpRecreateTask方法的典型用法代碼示例。如果您正苦於以下問題:Java NavUtils.shouldUpRecreateTask方法的具體用法?Java NavUtils.shouldUpRecreateTask怎麽用?Java NavUtils.shouldUpRecreateTask使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.support.v4.app.NavUtils的用法示例。


在下文中一共展示了NavUtils.shouldUpRecreateTask方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onOptionsItemSelected

import android.support.v4.app.NavUtils; //導入方法依賴的package包/類
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        // Respond to the action bar's Up/Home button
        case android.R.id.home:
            Intent upIntent = NavUtils.getParentActivityIntent(this);
            upIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
                // This activity is NOT part of this app's task, so create a new task
                // when navigating up, with a synthesized back stack.
                TaskStackBuilder.create(this)
                        // Add all of this activity's parents to the back stack
                        .addNextIntentWithParentStack(upIntent)
                        // Navigate up to the closest parent
                        .startActivities();
            } else {
                // This activity is part of this app's task, so simply
                // navigate up to the logical parent activity.
                NavUtils.navigateUpTo(this, upIntent);
            }
            return true;
    }
    return super.onOptionsItemSelected(item);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:25,代碼來源:FeedActivity.java

示例2: navigateUpOrBack

import android.support.v4.app.NavUtils; //導入方法依賴的package包/類
/**
 * This utility method handles Up navigation intents by searching for a parent activity and
 * navigating there if defined. When using this for an activity make sure to define both the
 * native parentActivity as well as the AppCompat one when supporting API levels less than 16.
 * when the activity has a single parent activity. If the activity doesn't have a single parent
 * activity then don't define one and this method will use back button functionality. If "Up"
 * functionality is still desired for activities without parents then use
 * {@code syntheticParentActivity} to define one dynamically.
 *
 * Note: Up navigation intents are represented by a back arrow in the top left of the Toolbar
 *       in Material Design guidelines.
 *
 * @param currentActivity Activity in use when navigate Up action occurred.
 * @param syntheticParentActivity Parent activity to use when one is not already configured.
 */
public static void navigateUpOrBack(Activity currentActivity,
                                    Class<? extends Activity> syntheticParentActivity) {
    // Retrieve parent activity from AndroidManifest.
    Intent intent = NavUtils.getParentActivityIntent(currentActivity);

    // Synthesize the parent activity when a natural one doesn't exist.
    if (intent == null && syntheticParentActivity != null) {
        try {
            intent = NavUtils.getParentActivityIntent(currentActivity, syntheticParentActivity);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
    }

    if (intent == null) {
        // No parent defined in manifest. This indicates the activity may be used by
        // in multiple flows throughout the app and doesn't have a strict parent. In
        // this case the navigation up button should act in the same manner as the
        // back button. This will result in users being forwarded back to other
        // applications if currentActivity was invoked from another application.
        currentActivity.onBackPressed();
    } else {
        if (NavUtils.shouldUpRecreateTask(currentActivity, intent)) {
            // Need to synthesize a backstack since currentActivity was probably invoked by a
            // different app. The preserves the "Up" functionality within the app according to
            // the activity hierarchy defined in AndroidManifest.xml via parentActivity
            // attributes.
            TaskStackBuilder builder = TaskStackBuilder.create(currentActivity);
            builder.addNextIntentWithParentStack(intent);
            builder.startActivities();
        } else {
            // Navigate normally to the manifest defined "Up" activity.
            NavUtils.navigateUpTo(currentActivity, intent);
        }
    }
}
 
開發者ID:dreaminglion,項目名稱:iosched-reader,代碼行數:52,代碼來源:BaseActivity.java

示例3: onOptionsItemSelected

import android.support.v4.app.NavUtils; //導入方法依賴的package包/類
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == android.R.id.home) {
        Intent upIntent = new Intent(this, MainActivity.class);
        if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
            // This activity is not part of the application's task, so create a new task
            // with a synthesized back stack.
            TaskStackBuilder.from(this)
                    .addNextIntent(upIntent)
                    .startActivities();
            finish();
        } else {
            // This activity is part of the application's task, so simply
            // navigate up to the hierarchical parent activity.
            NavUtils.navigateUpTo(this, upIntent);
        }
        return true;
    } else if (item.getTitle().equals("Settings")) {
        //startActivity(new Intent(this, Settings.class));
        finish();
        // overridePendingTransition(R.anim.hold, R.anim.push_out_to_left);
        return true;
    }
    return super.onOptionsItemSelected(item);
}
 
開發者ID:SalmanTKhan,項目名稱:MyAnimeViewer,代碼行數:26,代碼來源:AnimeDetailsActivity.java

示例4: onOptionsItemSelected

import android.support.v4.app.NavUtils; //導入方法依賴的package包/類
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            Intent upIntent = NavUtils.getParentActivityIntent(this);
            upIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
                TaskStackBuilder.create(this)
                        .addNextIntentWithParentStack(upIntent)
                        .startActivities();
            } else {
                NavUtils.navigateUpTo(this, upIntent);
            }
            return true;
    }
    return super.onOptionsItemSelected(item);
}
 
開發者ID:graviton57,項目名稱:TheNounProject,代碼行數:18,代碼來源:IconsActivity.java

示例5: onOptionsItemSelected

import android.support.v4.app.NavUtils; //導入方法依賴的package包/類
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {

        case android.R.id.home:
            Intent upIntent = NavUtils.getParentActivityIntent(this);
            if ( null != upIntent ) {
                upIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

                if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
                    // This activity is NOT part of this app's task, so create a new task
                    // when navigating up, with a synthesized back stack.
                    TaskStackBuilder.create(this)
                            // Add all of this activity's parents to the back stack
                            .addNextIntentWithParentStack(upIntent)
                            // Navigate up to the closest parent
                            .startActivities();
                }
                else {
                    // This activity is part of this app's task, so simply
                    // navigate up to the logical parent activity.
                    NavUtils.navigateUpTo(this, upIntent);
                }
            }
            else {
                onBackPressed();
            }


            return true;
    }

    return super.onOptionsItemSelected( item );
}
 
開發者ID:mithrilcoin-io,項目名稱:EosCommander,代碼行數:35,代碼來源:BaseActivity.java

示例6: navigateUp

import android.support.v4.app.NavUtils; //導入方法依賴的package包/類
public static void navigateUp(Activity activity, Bundle extras) {
    Intent upIntent = NavUtils.getParentActivityIntent(activity);
    if (upIntent == null) {
        com.hanyee.androidlib.utils.LogUtils.w("No parent found for activity, will just call finish(): "
                + activity.getClass().getName());
    } else {
        if (extras != null) {
            upIntent.putExtras(extras);
        }
        if (NavUtils.shouldUpRecreateTask(activity, upIntent)) {
            com.hanyee.androidlib.utils.LogUtils.i("Creating new task");
            // This activity is NOT part of this app's task, so create a new task
            // when navigating up, with a synthesized back stack.
            TaskStackBuilder.create(activity)
                    // Add all of this activity's parents to the back stack.
                    .addNextIntentWithParentStack(upIntent)
                    // Navigate up to the closest parent.
                    .startActivities();
        } else {
            // This activity is part of this app's task, so simply
            // navigate up to the logical parent activity.
            com.hanyee.androidlib.utils.LogUtils.i("Using original task");
            // According to http://stackoverflow.com/a/14792752/2420519
            //NavUtils.navigateUpTo(activity, upIntent);
            upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            activity.startActivity(upIntent);
        }
    }
    activity.finish();
}
 
開發者ID:HanyeeWang,項目名稱:GeekZone,代碼行數:31,代碼來源:AppUtils.java

示例7: navigateUp

import android.support.v4.app.NavUtils; //導入方法依賴的package包/類
private void navigateUp() {
    Intent upIntent = NavUtils.getParentActivityIntent(this);
    if (NavUtils.shouldUpRecreateTask(this, upIntent) || isTaskRoot()) {
        TaskStackBuilder.create(this).addNextIntentWithParentStack(upIntent).startActivities();
    } else {
        NavUtils.navigateUpTo(this, upIntent);
    }
}
 
開發者ID:ANFR-France,項目名稱:proto-collecte,代碼行數:9,代碼來源:ParcoursActivity.java

示例8: onOptionsHomeSelected

import android.support.v4.app.NavUtils; //導入方法依賴的package包/類
protected final void onOptionsHomeSelected() {
    Intent upIntent = NavUtils.getParentActivityIntent(this);
    if (null == upIntent) {
        finish();
    } else {
        if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
            TaskStackBuilder.create(this)
                    .addNextIntentWithParentStack(upIntent)
                    .startActivities();
        } else {
            upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            NavUtils.navigateUpTo(this, upIntent);
        }
    }
}
 
開發者ID:zxmmmmmm,項目名稱:Mvvm,代碼行數:16,代碼來源:MvvmActivity.java

示例9: supportShouldUpRecreateTask

import android.support.v4.app.NavUtils; //導入方法依賴的package包/類
public boolean supportShouldUpRecreateTask(@NonNull Intent targetIntent) {
    return NavUtils.shouldUpRecreateTask(this, targetIntent);
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:4,代碼來源:AppCompatActivity.java

示例10: onOptionsItemSelected

import android.support.v4.app.NavUtils; //導入方法依賴的package包/類
@Override
public boolean onOptionsItemSelected(MenuItem item) {
	switch (item.getItemId()) {
	case android.R.id.home:
		Intent upIntent = NavUtils.getParentActivityIntent(this);
		if (upIntent != null)
			if (NavUtils.shouldUpRecreateTask(this, upIntent))
				TaskStackBuilder.create(this).addNextIntentWithParentStack(upIntent).startActivities();
			else
				NavUtils.navigateUpTo(this, upIntent);
		return true;
	case R.id.menu_usage:
		optionUsage();
		return true;
	case R.id.menu_accounts:
		optionAccounts();
		return true;
	case R.id.menu_applications:
		optionApplications();
		return true;
	case R.id.menu_contacts:
		if (item.getGroupId() != 0) {
			optionContacts(item.getGroupId());
			return true;
		} else
			return false;
	case R.id.menu_whitelists:
		optionWhitelists(null);
		return true;
	case R.id.menu_apply:
		optionTemplate();
		return true;
	case R.id.menu_clear:
		optionClear();
		return true;
	case R.id.menu_export:
		optionExport();
		return true;
	case R.id.menu_import:
		optionImport();
		return true;
	case R.id.menu_submit:
		optionSubmit();
		return true;
	case R.id.menu_fetch:
		optionFetch();
		return true;
	case R.id.menu_settings:
		optionSettings();
		return true;
	case R.id.menu_dump:
		optionDump();
		return true;
	case R.id.menu_legend:
		optionLegend();
		return true;
	case R.id.menu_tutorial:
		optionTutorial();
		return true;
	default:
		return super.onOptionsItemSelected(item);
	}
}
 
開發者ID:ukanth,項目名稱:XPrivacy,代碼行數:64,代碼來源:ActivityApp.java

示例11: onOptionsItemSelected

import android.support.v4.app.NavUtils; //導入方法依賴的package包/類
@Override
public boolean onOptionsItemSelected(MenuItem item) {
	UsageTask usageTask;
	switch (item.getItemId()) {
	case android.R.id.home:
		Intent upIntent = NavUtils.getParentActivityIntent(this);
		if (upIntent != null)
			if (NavUtils.shouldUpRecreateTask(this, upIntent))
				TaskStackBuilder.create(this).addNextIntentWithParentStack(upIntent).startActivities();
			else
				NavUtils.navigateUpTo(this, upIntent);
		return true;

	case R.id.menu_usage_all:
		mAll = !mAll;
		if (mUsageAdapter != null)
			mUsageAdapter.getFilter().filter(Boolean.toString(mAll));
		return true;

	case R.id.menu_refresh:
		updateTitle();
		usageTask = new UsageTask();
		usageTask.executeOnExecutor(mExecutor, (Object) null);
		return true;

	case R.id.menu_clear:
		PrivacyManager.deleteUsage(mUid);
		usageTask = new UsageTask();
		usageTask.executeOnExecutor(mExecutor, (Object) null);
		return true;

	case R.id.menu_whitelists:
		if (Util.hasProLicense(this) == null) {
			// Redirect to pro page
			Util.viewUri(this, ActivityMain.cProUri);
		} else {
			WhitelistTask whitelistsTask = new WhitelistTask(mUid, null, this);
			whitelistsTask.executeOnExecutor(mExecutor, (Object) null);
		}
		return true;

	case R.id.menu_settings:
		Intent intent = new Intent(this, ActivitySettings.class);
		startActivity(intent);
		return true;

	default:
		return super.onOptionsItemSelected(item);
	}
}
 
開發者ID:ukanth,項目名稱:XPrivacy,代碼行數:51,代碼來源:ActivityUsage.java


注:本文中的android.support.v4.app.NavUtils.shouldUpRecreateTask方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。