0
我想嘗試使用系統服務,如wakelock,但由於某種原因,當我運行它的錯誤說「系統服務不可用的onCreate()之前的活動()」我試着改變一點點wakelock通過將newWakeLock移動到oncreate()
來解決問題,但這仍然無效,有什麼可以解決這個問題?Android系統服務不可用錯誤
public class MainActivity extends ListActivity {
String[] activities = {"package1", "package2", "package3"};
private PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
//@SuppressWarnings("deprecation")
private PowerManager.WakeLock wakeLock; //= powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "My Tag");
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "My Tag");
wakeLock.acquire();
this.setListAdapter(new ArrayAdapter (this, android.R.layout.simple_expandable_list_item_1, activities));
}
public void onPause(){
wakeLock.release();
}
public void onResume(){ }
public void onDestroy(){ }
/* public void onListItemClick(ListView, View, int, long){ }*/
}