我想尝试使用诸如唤醒锁之类的系统服务,但是由于某种原因,当我运行它时出现错误提示“系统服务在 onCreate() 之前对活动不可用”我尝试更改一些唤醒锁以查看它是否可以通过移动来修复它newWakeLock 进入oncreate()
但仍然无法正常工作,有什么办法可以解决这个问题?
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){ }*/
}