2010-10-11 23 views
40

मैं टैब के अंदर मौजूद दो गतिविधियों के बीच डेटा पास करने की कोशिश कर रहा हूं। मैं sendBroadcast का उपयोग करने की कोशिश कर रहा हूँ। ब्रेकपॉइंट्स सेट के साथ मैं कभी भी ऑनरसीव तक नहीं पहुंचता।प्रसारण संदेश कैसे भेजें और प्राप्त करें

प्रकट:

<activity 
    android:name=".WebResults" 
    android:label="@string/app_name"> 

    <intent-filter> 
     <action android:name="com.toxy.LOAD_URL" /> 
    </intent-filter>   
</activity> 

गतिविधि प्रेषक:

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

गतिविधि रिसीवर:

@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); 
    } 
} 
+0

टैब के लिए अलग-अलग गतिविधियों का उपयोग करने के बजाय सबकुछ एक गतिविधि में रखें, और अब आपको उनके बीच संवाद करने के लिए प्रसारण का उपयोग करने की आवश्यकता नहीं होगी। – CommonsWare

उत्तर

35

मैं आप के रूप में एक ही समस्या हो रही थी, लेकिन मैं पता लगा:

इन्हें हटाएं प्रकट से तम्बू फिल्टर और बदल

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

के लिए

Intent intent=new Intent();

आशा है कि यह मदद करता है!

7

का उपयोग करें

intent.getStringExtra(""); 

और

new Intent(); 

मेरे लिए काम किया।

+0

खाली कन्स्ट्रक्टर के साथ संकेत के लिए धन्यवाद, मैं लगभग पागल हो गया .. –

संबंधित मुद्दे