当前位置: 首页>>代码示例>>Java>>正文


Java NavUtils.navigateUpTo方法代码示例

本文整理汇总了Java中android.support.v4.app.NavUtils.navigateUpTo方法的典型用法代码示例。如果您正苦于以下问题:Java NavUtils.navigateUpTo方法的具体用法?Java NavUtils.navigateUpTo怎么用?Java NavUtils.navigateUpTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.support.v4.app.NavUtils的用法示例。


在下文中一共展示了NavUtils.navigateUpTo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: onOptionsItemSelected

import android.support.v4.app.NavUtils; //导入方法依赖的package包/类
@Override
public boolean onOptionsItemSelected(MenuItem item) {
  int id = item.getItemId();
  if (id == android.R.id.home) {
    // This ID represents the Home or Up button. In the case of this
    // activity, the Up button is shown. Use NavUtils to allow users
    // to navigate up one level in the application structure. For
    // more details, see the Navigation pattern on Android Design:
    //
    // http://developer.android.com/design/patterns/navigation.html#up-vs-back
    //
    NavUtils.navigateUpTo(this, new Intent(this, SimpleListActivity.class));
    return true;
  }
  return super.onOptionsItemSelected(item);
}
 
开发者ID:charlesng,项目名称:SampleAppArch,代码行数:17,代码来源:SimpleDetailActivity.java

示例3: onOptionsItemSelected

import android.support.v4.app.NavUtils; //导入方法依赖的package包/类
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == android.R.id.home) {
        // This ID represents the Home or Up button. In the case of this
        // activity, the Up button is shown. Use NavUtils to allow users
        // to navigate up one level in the application structure. For
        // more details, see the Navigation pattern on Android Design:
        //
        // http://developer.android.com/design/patterns/navigation.html#up-vs-back
        //
        NavUtils.navigateUpTo(this, new Intent(this, ItemListActivity.class));
        return true;
    }
    return super.onOptionsItemSelected(item);
}
 
开发者ID:smartbeng,项目名称:PaoMovie,代码行数:17,代码来源:ItemDetailActivity.java

示例4: 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

示例5: 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

示例6: 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

示例7: showDiaryView

import android.support.v4.app.NavUtils; //导入方法依赖的package包/类
@Override
public void showDiaryView() {
    getActivity().setResult(Activity.RESULT_OK);
    if(getActivity().getIntent().getBooleanExtra(FROM_MAIN_ACTIVITY, false)) {
        getActivity().finish();
    }
    else {
        // Navigate up to MainActivity with a new intent to view the diary tab
        Intent intent = NavUtils.getParentActivityIntent(getActivity());
        intent.putExtra(MainActivity.REQUESTED_TAB_NAME, getResources().getString(R.string.diary_tab_name));
        NavUtils.navigateUpTo(getActivity(), intent);
    }
}
 
开发者ID:jgevans,项目名称:TherapyGuide,代码行数:14,代码来源:EditDiaryEntryFragment.java

示例8: 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

示例9: onOptionsItemSelected

import android.support.v4.app.NavUtils; //导入方法依赖的package包/类
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            NavUtils.navigateUpTo(this, new Intent(this, MainActivity.class));
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
 
开发者ID:cdc03819,项目名称:BrewBook,代码行数:11,代码来源:SettingsActivity.java

示例10: 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

示例11: onOptionsItemSelected

import android.support.v4.app.NavUtils; //导入方法依赖的package包/类
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == android.R.id.home) {

        savedata();

        Intent intent = NavUtils.getParentActivityIntent(this).putExtra("delay", 5);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        NavUtils.navigateUpTo(this, intent);
        return true;
    }
    return super.onOptionsItemSelected(item);
}
 
开发者ID:maricabral,项目名称:GemFX,代码行数:15,代码来源:SettingsActivity.java

示例12: 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

示例13: onOptionsItemSelected

import android.support.v4.app.NavUtils; //导入方法依赖的package包/类
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            Intent up = NavUtils.getParentActivityIntent(this);
            up.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
            NavUtils.navigateUpTo(this, up);
            return true;
    }
    return super.onOptionsItemSelected(item);
}
 
开发者ID:Maxr1998,项目名称:home-assistant-Android,代码行数:12,代码来源:SettingsActivity.java

示例14: 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

示例15: supportNavigateUpTo

import android.support.v4.app.NavUtils; //导入方法依赖的package包/类
public void supportNavigateUpTo(@NonNull Intent upIntent) {
    NavUtils.navigateUpTo(this, upIntent);
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:4,代码来源:AppCompatActivity.java


注:本文中的android.support.v4.app.NavUtils.navigateUpTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。