gpt4 book ai didi

android - 当我们从 Fragment 类调用 facebook 或 twitter 时如何处理后退按钮?

转载 作者:太空宇宙 更新时间:2023-11-03 11:14:38 24 4
gpt4 key购买 nike

我想从 fragment 连接 Facebook 和 Twitter,但是当我从 Facebook 或 Twitter 返回时应用程序关闭。我想留在那个应用程序中。

我的代码在这里...

 @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;
}
}

最佳答案

我的问题在这里得到解决是我在 list 文件中的实际代码

<activity
android:name="com.example.AdslistScreen"
android:label="@string/app_name"
android:noHistory="true"
android:screenOrientation="portrait"></activity>

因为这行 android:noHistory="true" 当我调用 facebook 时,我以前的历史记录将被清除,所以当我返回我的应用程序时,它将关闭整个应用程序。现在我删除这个android:noHistory="true" 行我的代码工作正常。

谢谢大家

关于android - 当我们从 Fragment 类调用 facebook 或 twitter 时如何处理后退按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18388170/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com