Shikha Ratra
Shikha Ratra

Reputation: 695

Using Intent.createChooser close the activity

I am using Intent.createChooser to share the content.Then share Intent.createChooser dialog appear and work fine but when i press back button to close the dialog, it finishes the activity. I want to prevent the Activity from closing just want to close the Intent.createChooser dialog. The onclick event is in the Recyclerview.

 shareButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //align the selection to the
                Intent shareIntent = new Intent(Intent.ACTION_SEND);
                shareIntent.setType("text/plain");
                shareIntent.putExtra(Intent.EXTRA_TEXT, items.get(position).getShareUrl());
                context.startActivity(Intent.createChooser(shareIntent, "Share with"));
            }
        });


<?xml version="1.0" encoding="utf-8"?>

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.CLEAR_APP_CACHE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />

<supports-screens>
    android:resizeable="true"
    android:smallScreens="true"
    android:normalScreens="true"
    android:largeScreens="true"
    android:xlargeScreens="true"
    android:anyDensity="true"
</supports-screens>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity
        android:name=".MainActivity"
        android:configChanges="keyboardHidden|orientation|screenSize"
        android:hardwareAccelerated="true"
        android:largeHeap="true"
        android:launchMode="singleTop"
        android:noHistory="true"
        android:screenOrientation="portrait"
        android:showAsAction="ifRoom|withText">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

Upvotes: 1

Views: 1686

Answers (1)

Divers
Divers

Reputation: 9569

Remove android:noHistory="true" from MainActivity in your manifest file.

Upvotes: 5

Related Questions