package com.example.android.sunshine.app;

import android.content.Intent;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.support.v7.widget.ShareActionProvider;
import android.view.Menu;
import android.view.MenuItem;


public class DetailActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_detail);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_detail, menu);
        MenuItem shareItem = menu.findItem(R.id.action_share);
        if (shareItem!=null) {
            ShareActionProvider shareAP = (ShareActionProvider)
                    MenuItemCompat.getActionProvider(shareItem);
            shareAP.setShareIntent(getShareIntent());
        }
        return true;
    }

    private Intent getShareIntent() {
        Intent shareIntent = new Intent(Intent.ACTION_SEND);
        shareIntent.setType("text/*");
        final Intent in = getIntent();
        String forecast = null;
        if (in!=null) {
             forecast = in.getStringExtra(ForecastFragment.FORECAST_STRING);
        }
        final String hashtag = "#SunshineApp";
        final String shareText =
                (forecast==null || forecast.isEmpty()) ? hashtag : forecast + " " + hashtag;
        shareIntent.putExtra(Intent.EXTRA_TEXT, shareText);
        return shareIntent;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.

        switch (item.getItemId()) {
            case R.id.action_settings: {
                startActivity(new Intent(this, SettingsActivity.class));
                return true;
            }
        }

        return super.onOptionsItemSelected(item);
    }
}

@@ -1153,16 +1153,151 @@
 _SEND);%0A
+        //noinspection deprecation since we target older API%0A        shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);%0A
         
@@ -1326,9 +1326,13 @@
 ext/
-*
+plain
 %22);%0A

Use appropriate flag and more specific type