Android System Services not available error -


i want try use system service such wakelock reason when run errors saying "system services not available activities before oncreate()" tried changing little of wakelock see if fix moving newwakelock oncreate() still not work, can fix this?

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){    }*/     } 

this line :

 powermanager = (powermanager) getsystemservice(context.power_service); 

should placed in oncreate method.

before that, activity not alive , doesn't have access android services.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -