Jak wysyłać i odbierać wiadomości nadawcze
Próbuję przekazać dane między dwoma działaniami, które znajdują się wewnątrz kart. Próbuję użyć sendBroadcast()
. Z ustawionymi punktami przerwania nigdy nie osiągam onReceive()
.
Manifest:
<activity
android:name=".WebResults"
android:label="@string/app_name">
<intent-filter>
<action android:name="com.toxy.LOAD_URL" />
</intent-filter>
</activity>
Aktywność Nadawcy:
Intent intent=new Intent(getApplicationContext(),WebResults.class);
intent.setAction("com.toxy.LOAD_URL");
intent.putExtra("url",uri.toString());
sendBroadcast(intent);
Odbiorca Aktywności:
@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);
}
}
42
2 answers
Miałem ten sam problem co ty, ale się domyśliłem:
Usuń filtr intencji z manifestu i zmień
Intent intent=new Intent(getApplicationContext(),WebResults.class);
Dla
Intent intent=new Intent();
37
Author: Paulo Cesar,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-04-04 13:30:52
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-04-04 13:30:52
Proszę użyć
intent.getStringExtra("");
I
new Intent();
Zadziałało dla mnie. 7
Author: Abdul,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-01-03 22:56:09
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-01-03 22:56:09