Reputation: 25
I am working on implementing the Facebook SDK for my app. My problem is that the Share Dialog appears as soon as the app finishes loading. I want the ShareDialog to only appear when the button is pressed, it does this. But again, I don't want it to appear immediately, this can get very annoying.
This is my code:
public class MainActivity extends AppCompatActivity {
CallbackManager callbackManager;
ShareDialog shareDialog;
ShareLinkContent linkContent;
@Override
protected void onCreate(Bundle savedInstanceState) {
FacebookSdk.sdkInitialize(getApplicationContext());
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
callbackManager = CallbackManager.Factory.create();
shareDialog = new ShareDialog(this);
AppEventsLogger.activateApp(this);
if (ShareDialog.canShow(ShareLinkContent.class)) {
linkContent = new ShareLinkContent.Builder()
.setContentTitle("")
.setContentDescription(
"")
.setContentUrl(Uri.parse("https://www.facebook.com/globalwidemusiccom-116137701783410/"))
.build();
shareDialog.show(linkContent);
}
ShareButton shareButton = (ShareButton)findViewById(R.id.fb_share_button);
shareButton.setShareContent(linkContent);
LikeView likeView = (LikeView) findViewById(R.id.like_view);
likeView.setObjectIdAndType(
"https://www.facebook.com/globalwidemusiccom-116137701783410/",
LikeView.ObjectType.PAGE);
WebView webView = (WebView) findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl("https://globalwidemusic.com/AppGlobalWideMusic/index.html");
MobileAds.initialize(getApplicationContext(), "ca-app-pub-8679652085375496~2353468367");
AdView mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
//new global wide music
}
@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}
}
I am sorry there is so much, I am not sure what to do, I have tried displaying the ShareDialog with onClick, but then it did not display at all. Any tips or code would help greatly. Thank you.
Sincerely, Alex
Upvotes: 1
Views: 96
Reputation: 14274
Remove shareDialog.show(linkContent);
from your onCreate()
and place it in your onClick()
.
Upvotes: 1