Skip to content Skip to sidebar Skip to footer

Flag_activity_new_task Flag Error For Sharing In Custom Spinner

i want to use share button in custom spinner it's my code: btnShareCS_One.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { //

Solution 1:

use it

// Share Selected Item In Cell-PhoneIntentsharingIntent=newIntent(android.content.Intent.ACTION_SEND);
            sharingIntent.setType("text/plain");
            StringshareBody= note.title + ":" + "\n" + note.detail;
            // sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, note.title + ":");
            sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
            sharingIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            G.currentActivity.startActivity(Intent.createChooser(sharingIntent, "اشتراک با..."));

And G.currentActivity

G

Is Global Class Extends Application And

currentActivity

is static Variable From Activity

Solution 2:

You just have to uncomment the line

sharingIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

You are having this problem because you're calling the method startActivity() from outside of an Activity without the flag FLAG_ACTIVITY_NEW_TASK.

Solution 3:

Whenever you used Intent from non Activity class then there is need to add below mentioned line to convey that we are calling Activity from Non Activity

sharingIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

Thanks

Solution 4:

Intentintent=newIntent();
            intent.setAction(Intent.ACTION_SEND);
            intent.setType("text/plain");

            StringtextMessage="Text Of Message";
            intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject");
            intent.putExtra(Intent.EXTRA_TEXT, textMessage);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.getApplicationContext().startActivity(intent);

Post a Comment for "Flag_activity_new_task Flag Error For Sharing In Custom Spinner"