I call ShareDialog by the same way from 2 activities: MainActivity and ReleaseActivity, but behavior is different: from MainActivity I share to facebook app, but from ReleaseActivity can't do that. Callback to catch result (for testing)
callbackManager = CallbackManager.Factory.create();
shareDialog = new ShareDialog(this);
shareDialog.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() {
@Override
public void onSuccess(Sharer.Result result) {
Log.d("Tracing", "ReleaseActivity 63 onSuccess");
}
@Override
public void onCancel() {
Log.d("Tracing", "ReleaseActivity 68 onCancel");
}
@Override
public void onError(FacebookException e) {
Log.d("Tracing", "ReleaseActivity 74 onError " + e.toString());
e.printStackTrace();
}
});
Code for ShareDialog:
if (ShareDialog.canShow(ShareLinkContent.class)) {
Log.d("Tracing", "ReleaseActivity 100 facebookOnClick");
ShareLinkContent linkContent = new ShareLinkContent.Builder()
.setContentTitle("Test title")
.setContentDescription(
"Test text-description")
.setContentUrl(Uri.parse("http://developers.facebook.com/android"))
.build();
shareDialog.show(linkContent);
Log.d("Tracing", "ReleaseActivity 110 facebookOnClick");
}
Log.d("Tracing", "ReleaseActivity 111 facebookOnClick end");
};
In both activities after pressing facebook button I see logs in ShareDialog's code, in MainActivity Facebook window pop-up, but not in ReleaseActivity.
I don't see facebook window but after pressing on facebook button I press android Overview button to see launched apps and see facebook app (with black screen), when I press on this facebook black screen it disappears. https://www.dropbox.com/s/sn0tlqhgce5za7o/fc.jpg?dl=0
Callback show me result only in MainActivity. Android SDK 4.14.1
Why it works in one case and doesn't work in another? What to do?
I don't know why but it started to work when I wrote class ReleaseActivity extends BaseActivity
as MainActivity has, instead of class ReleaseActivity extends Activity
BaseActivity: class BaseActivity extends AppCompatActivity
.
So, classes that extend AppCompatActivity
work with Facebook SDK, and classes that don't do that - don't work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.