I want to associate Facebook and Twitter with the fragment, but when I returned from Facebook or Twitter, the application is closed. I want to stay in this application.
my code is here ...
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_rssitem_detail,container, false); Button facebook=(Button)view .findViewById(R.id.facebook); facebook.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND); shareIntent.setType("text/plain"); shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Some text"); shareIntent.putExtra(android.content.Intent.EXTRA_TEXT,"http://www.gogole.com"); final PackageManager pm = v.getContext().getPackageManager(); final List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0); for (final ResolveInfo app : activityList) { if ("com.facebook.katana.ShareLinkActivity".equals(app.activityInfo.name)) { final ActivityInfo activity = app.activityInfo; final ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name); shareIntent.addCategory(Intent.CATEGORY_LAUNCHER); shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); shareIntent.setComponent(name); startActivity(shareIntent); break; }} } }); Button twitter=(Button)view.findViewById(R.id.twitter); twitter.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND); shareIntent.setType("text/plain"); shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Some text"); shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "www.google.com"); final PackageManager pm = v.getContext().getPackageManager(); final List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0); for (final ResolveInfo app : activityList) { if ("com.twitter.android.PostActivity".equals(app.activityInfo.name)) { final ActivityInfo activity = app.activityInfo; final ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name); shareIntent.addCategory(Intent.CATEGORY_LAUNCHER); shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); shareIntent.setComponent(name); startActivity(shareIntent); break; } } } }); return view; } }
Seshu source share