0
我正在嘗試做一個小部件,它會對ACTION_SCREEN_ON/_OFF
做出反應。我試圖在清單中聲明BroadcastReceiver
,但它不起作用。我讀過的地方應該用代碼註冊。我寫道:BroadcastReceiver on Application.onCreate()
public class TimeTableApp extends Application {
public void OnCreate() {
Log.d("FinWi","appOncreate");
Context cnt = this.getApplicationContext();
IntentFilter intentFilter = new IntentFilter(Intent.ACTION_SCREEN_ON);
intentFilter.addAction(Intent.ACTION_SCREEN_OFF);
intentFilter.addAction(Intent.ACTION_DATE_CHANGED);
BroadcastReceiver mReceiver = new ScreenStateBroadcastReceiver();
cnt.registerReceiver(mReceiver, intentFilter);
super.onCreate();
}
}
<application android:name=".TimeTableApp"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<receiver android:name=".TimeTableWidgetProvider">
<meta-data android:name="android.appwidget.provider"
android:resource="@xml/appwidget_provider" />
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
</receiver>
</application>`
它不叫onCreate()
。
的onCreate()......但在OnCreate().. – rusCrypto 2012-03-04 07:36:19
其他一切正常 – rusCrypto 2012-03-04 07:36:35
你實際上並沒有重寫oncreate,因爲它需要BUndle作爲參數,,,, – 2012-03-04 19:50:49