-1

我在 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;
        }
    }

是否有任何可用的意图标志或需要进行一些更改。请帮帮我。谢谢。

4

1 回答 1

0

您的应用程序是否因为不响应共享结果而崩溃?您应该显示您的日志。

我猜这是正常行为,并且正在向您的应用程序发送返回请求,使其退出,因为这是下一步。你可以抓住退出请求,做你喜欢的事。

    @Override
    public void exit()
    {
        Log.e(TAG, "exit");
    }

也许你真的要退出是|否的行上的警告对话框。另请参见 onPause()。

也尝试使用:

    public static final int     ACTIVITY_CREATE       = 0;

Intent i = Intent.createChooser(shareIntent, "Share via");
 startActivityForResult(i, ACTIVITY_CREATE);

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent intent)
    {
        if(resultCode == RESULT_CANCELED)
        {
            Log.e(TAG, "onActivityResult RESULT_CANCELED");
        }
        switch (requestCode)
        {
            case ACTIVITY_CREATE:
                if (resultCode == RESULT_OK)
                {
                    Log.v(TAG, "onActivityResult ACTIVITY_CREATE");
                }
                break;
....
于 2016-07-15T13:59:08.170 回答