如何处理后退按钮当我们调用Facebook或Twitter从片段类? [英] how to handle back button when we call facebook or twitter from the Fragment class?
问题描述
我想Facebook和Twitter的片段连接起来,但是当我从Facebook或Twitter回来的应用是closed.I想留在该应用程序。
我的code是这里...
@覆盖
公共查看onCreateView(LayoutInflater充气器,容器的ViewGroup,捆绑savedInstanceState){
查看查看= inflater.inflate(R.layout.fragment_rssitem_detail,集装箱,FALSE);
按钮的Facebook =(按钮)查看.findViewById(R.id.facebook);
facebook.setOnClickListener(新OnClickListener(){
@覆盖
公共无效的onClick(视图v){
// TODO自动生成方法存根 意图shareIntent =新意图(android.content.Intent.ACTION_SEND);
shareIntent.setType(text / plain的);
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,一些文字);
shareIntent.putExtra(android.content.Intent.EXTRA_TEXThttp://www.gogole.com); 最终的软件包管理系统PM = v.getContext()getPackageManager()。
最终名单< ResolveInfo> activityList = pm.queryIntentActivities(shareIntent,0);
对于(最终ResolveInfo应用:activityList){
如果(com.facebook.katana.ShareLinkActivity.equals(app.activityInfo.name)){
最后ActivityInfo活性= app.activityInfo;
最终的组件名NAME =新的组件名(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(名);
startActivity(shareIntent);
打破;
}}
}
}); 按钮叽叽喳喳=(按钮)view.findViewById(R.id.twitter);
twitter.setOnClickListener(新OnClickListener(){ @覆盖
公共无效的onClick(视图v){
意图shareIntent =新意图(android.content.Intent.ACTION_SEND);
shareIntent.setType(text / plain的);
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,一些文字);
shareIntent.putExtra(android.content.Intent.EXTRA_TEXTwww.google.com);
最终的软件包管理系统PM = v.getContext()getPackageManager()。
最终名单< ResolveInfo> activityList = pm.queryIntentActivities(shareIntent,0);
对于(最终ResolveInfo应用:activityList){
如果(com.twitter.android.PostActivity.equals(app.activityInfo.name)){
最后ActivityInfo活性= app.activityInfo;
最终的组件名NAME =新的组件名(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(名);
startActivity(shareIntent);
打破;
}
}
}
});返回视图。
}
}
我的问题在这里解决的就是清单文件我的实际code
<活动
机器人:名字=com.example.AdslistScreen
机器人:标签=@字符串/ APP_NAME
机器人:noHistory =真
机器人:screenOrientation =肖像>< /活性GT;
由于此行的的android:noHistory =真正的我的previous历史将在我打电话的Facebook所以,当我回到我的应用程序将被关闭整个应用程序被清除我。现在删除此
的android:noHistory =真正的行我的code是工作的罚款。
Thanku所有
I want to connect Facebook and Twitter from fragment, but when I came back from Facebook or Twitter the application is closed.I want to stay in that 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;
}
}
My issue is solved here is my Actual code in manifest file
<activity
android:name="com.example.AdslistScreen"
android:label="@string/app_name"
android:noHistory="true"
android:screenOrientation="portrait"></activity>
Because of this line android:noHistory="true" my previous history will be cleared when i'm calling facebook so when i come back to my application it will be closed entire application.Now i remove this android:noHistory="true" line my code is working fine.
Thanku all
这篇关于如何处理后退按钮当我们调用Facebook或Twitter从片段类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!