Thanks, attatching the broadcastReciever at runtime seems to work, but i could not get it to work when i tried to bind it in the manifest xml.
This works :
In my activity i added:
private MyReceiver reciever;
protected void onPause(){
super.onPause();
unregisterReceiver(reciever);
}
protected void onStart(){
super.onStart();
reciever = new MyReceiver(this);
registerReceiver(reciever, new IntentFilter("Gurba"));
}
//...attatched to button...
public void onClick(View arg0) {
Log.i("dbg", "clickkkk");
Intent myIntent = new Intent("Gurba");
sendBroadcast(myIntent);
}
And my MyReciever class as follow:
public class MyReceiver extends BroadcastReceiver {
private Activity activity;
public MyReceiver(Activity activity) {
this.activity = activity;
Log.i("dbg","MyReciever created");
}
public void onReceive(Context context, Intent intent) {
Log.i("dbg","onRecieve() called!");
if(this.activity == null);
}
}
This did NOT work:
private MyReceiver reciever;
protected void onPause(){
super.onPause();
}
protected void onStart(){
super.onStart();
reciever = new MyReceiver(this);
}
and added to the AndroidManifest.xml
<application
android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">
<receiver android:name=".MyReceiver">
<intent-filter>
<action android:name="Gurba" />
</intent-filter>
</receiver>
<activity android:name=".Main" ... continue manifest...
when i click my button i just get a runtime-exception:
unable to instantiate receiver com.example.MyReciever ....
Any ideas on this? Something missing in my XML?