How Can I Load Webview Url In Fragment From Another Appcompatactivity Class
I am creating project for 'Drawer with Swipe Tab'. There i used a webview in fragment and i want to load Webview URL from Another AppCompatActivity. How can i do it? Fragment Class
Solution 1:
Use localBroadCastManager
WebViewHavingActivity
@OverrideprotectedvoidonPause() {
// Unregister since the activity is paused.LocalBroadcastManager.getInstance(this).unregisterReceiver(
mWebViewLoader);
super.onPause();
}
@OverrideprotectedvoidonResume() {
// Register to receive messages.// We are registering an observer (mWebViewLoader) to receive Intents// with actions named "WebView".LocalBroadcastManager.getInstance(this).registerReceiver(
mWebViewLoader, newIntentFilter("WebView"));
super.onResume();
}
// Our handler for received Intents. This will be called whenever an Intent// with an action named "WebView" is broadcasted.privateBroadcastReceiver mWebViewLoader = newBroadcastReceiver() {
@OverridepublicvoidonReceive(Context context, Intent intent) {
mWebView.post(newRunnable() {
@Overridepublicvoidrun() {
mWebView.loadUrl("http://google.com");
}
});
}
};
CallingActivity
LocalBroadcastManager.getInstance(JobDetailScreen.this).sendBroadcast(newIntent("WebView"));
Solution 2:
This Work for me Thanks For trying me to Help
SocialFragment.mWebView.post(new Runnable() {
publicvoidrun() {
SocialFragment.mWebView.loadUrl("http://www.busindia.com/busindia_TNSTC.jsp");
}
});
Post a Comment for "How Can I Load Webview Url In Fragment From Another Appcompatactivity Class"