Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send and receive broadcast message

I am trying to pass data between two activities that are inside of tabs. I am trying to use sendBroadcast(). With breakpoints set I never reach onReceive().

Manifest:

<activity     android:name=".WebResults"     android:label="@string/app_name">      <intent-filter>         <action android:name="com.toxy.LOAD_URL" />     </intent-filter>          </activity> 

Activity Sender:

Intent intent=new Intent(getApplicationContext(),WebResults.class); intent.setAction("com.toxy.LOAD_URL"); intent.putExtra("url",uri.toString()); sendBroadcast(intent); 

Activity Receiver :

@Override public void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);         IntentFilter filter = new IntentFilter("com.toxy.LOAD_URL");     this.registerReceiver(new Receiver(), filter); }  private class Receiver extends BroadcastReceiver {      @Override     public void onReceive(Context arg0, Intent arg1) {         String url = arg1.getExtras().getString("url");         WebView webview =(WebView)findViewById(R.id.webView);         webview.loadUrl(url);     } } 
like image 420
Yack Avatar asked Oct 11 '10 15:10

Yack


1 Answers

I was having the same problem as you, but I figured out:

Remove the intent filter from the manifest and change

Intent intent=new Intent(getApplicationContext(),WebResults.class); 

for

Intent intent=new Intent(); 

Hope it helps!

like image 62
Paulo Cesar Avatar answered Sep 20 '22 15:09

Paulo Cesar