wakelock などのシステム サービスを使用したいのですが、何らかの理由で実行すると、「システム サービスは 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){ }*/
}