我有以下活動類:安卓:如何創建廣播接收機作爲一個內部類的活動
public class Main extends TabActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
public class LocationUpdateReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "broadcast received", Toast.LENGTH_LONG).show();
Log.e("ADNAN", "received");
}
}
}
,並按照我的清單文件條目:
<receiver android:name=".LocationUpdateReceiver" android:enabled="true"/>
我用以下代碼向我的班級發送廣播:
Intent intent = new Intent(this,LocationUpdateReceiver.class);
sendBroadcast(intent);
但接收方沒有收到廣播。但是,如果我將我的接收器類放入其自己的文件中,即LocationUpdateReceiver.java,那麼它將按預期工作。我在這裏做錯了什麼?我需要以我的清單文件中的某種不同方式指定我的接收器嗎?我如何創建廣播接收器作爲內部類?
我不想這樣做,但我想它不可能的其他方式。 – binW 2011-05-14 13:33:53
使用某些API時,並不是要做你想做的事。祝你好運 ;) – 2011-05-14 13:39:33