Share Intent destroys Activity

376 views Asked by At

I am using several share intents in my application but when ever I share and my application moves in background and after sharing the activity destroys. I've tried:

android:configChanges="orientation|keyboardHidden|screenSize"

and

android:noHistory="true"

for the particular activity and calling explicit intents like e.g for (google+, facebook, twitter and email)

startActivityForResult(Intent.createChooser(intent,"Send mail..."),4);

and my ActivityOnResult

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(requestCode==FB_SIGN_ING){
        callbackManager.onActivityResult(requestCode,resultCode,data);
    } //else do nothing
}

Update: Ive figured it out a little bit my activity destroys when move to background to front. but how to handle it even if I m using particular configurations and ActivityOnResult.

intent Example:

public void ShareByEmail(){
        final String newsTitle = singleNews.get(0).getNews_title().trim();
        String newsPhoto=SingleNewsImages.get(0);
        String url = BASE_URL+newsPhoto;
        final String newsLink = "http://motorcityarabia.com"+singleNews.get(0).getLink().trim();
        final Uri uri = Uri.parse(url);
        Target target = new Target() {
            @Override public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {

               // Intent intent = new Intent(Intent.ACTION_SENDTO,Uri.parse("mailto:"));
                Intent intent = new Intent();
              intent.setAction(Intent.ACTION_SEND);
                intent.putExtra(Intent.EXTRA_SUBJECT,newsTitle);
                intent.putExtra(Intent.EXTRA_TEXT , Html.fromHtml("<strong><a href='"+newsLink+"'>"+newsTitle+"</a></strong><br/><a href='"+newsLink+"'>READ MORE</a>"));

                intent.putExtra(Intent.EXTRA_STREAM, getLocalBitmapUri(bitmap));
                intent.setType("image/*");
                startActivityForResult(Intent.createChooser(intent,"Send mail..."),4);


            }
            @Override public void onBitmapFailed(Drawable errorDrawable) {
                Toast.makeText(SingleNewsActivity.this, "Error Drawable", Toast.LENGTH_SHORT).show();
            }
            @Override public void onPrepareLoad(Drawable placeHolderDrawable) {
                Toast.makeText(SingleNewsActivity.this, "Prepairing Image", Toast.LENGTH_SHORT).show();
            }
        };
        Picasso.with(getApplicationContext()).load(url).into(target);


    }
1

There are 1 answers

1
Pradeep P On

Add following in your manifiest

 <application......android:noHistory="false">....</application>