我在 MainActivity 中使用 materialTabHost 和 viewPager 来获得可滑动的标签视图。我还添加了导航抽屉。当我单击导航抽屉中列出的任何项目时,它将打开相关片段。当我点击返回时,它会将我带到 MainActivity。但这里的问题是共享意图,它也列在导航抽屉中。当我单击共享时,它会打开共享对话框,但是通过按后退按钮,它不会引导我进入 MainActivity,而是应用程序关闭。
以下是相关代码:
...........
mDrawerToggle = getActionBarDrawerToggle();
mDrawerLayout.setDrawerListener(mDrawerToggle);
mDrawerList = (ListView) findViewById(R.id.list_drawer);
mListTitles = new String[]{
getString(R.string.title_section1),
getString(R.string.title_section2),
getString(R.string.title_section3),
getString(R.string.title_section4),
getString(R.string.title_section5),
};
mDrawerList.setAdapter(new ArrayAdapter<>(this,
R.layout.drawer_list_item, mListTitles));
.....
void newFragment(int position) {
switch (position) {
case 0:
mFragment = new VideoFragment(AppGlobals.DIRECTORY.VIDEOS);
mViewPager.removeAllViews();
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.executePendingTransactions();
fragmentManager.beginTransaction().replace(R.id.container, mFragment).commit();
break;
case 1:
mFragment = new VideoFragment(AppGlobals.DIRECTORY.PICTURES);
mViewPager.removeAllViews();
FragmentManager fragmentManager2 = getSupportFragmentManager();
fragmentManager2.executePendingTransactions();
fragmentManager2.beginTransaction().replace(R.id.container, mFragment).commit();
break;
case 2:
mFragment = new SettingFragment();
mViewPager.removeAllViews();
FragmentManager fragmentManager3 = getSupportFragmentManager();
fragmentManager3.executePendingTransactions();
fragmentManager3.beginTransaction().replace(R.id.container, mFragment).commit();
break;
case 3:
mFragment = new AboutFragment();
mViewPager.removeAllViews();
FragmentManager fragmentManager4 = getSupportFragmentManager();
fragmentManager4.executePendingTransactions();
fragmentManager4.beginTransaction().replace(R.id.container, mFragment).commit();
break;
case 4:
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
StringBuilder shareBody = new StringBuilder().append("Hey, I just downloaded abc app. Really awesome app for Background/Silent video recording. Helpful for stopping bribe takers. Download from below link: https://play.google.com/store/apps/details?id=").append(getPackageName().toString());
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "abc app [High Definition]");
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody.toString());
startActivity(Intent.createChooser(shareIntent, "Share via"));
break;
default:
return;
}
}
是否有任何可用的意图标志或需要进行一些更改。请帮帮我。谢谢。