Sunday, 15 February 2015

android - Partial wake lock not working -


I have written this code to wake up my activity when it is turned off on the screen.

  Private PowerManager MPM; Private Power Manager. WakeLock mPartialWakeLock; @ Override public viewcreatives (layoutInflator Inflator, View Group Container, Bundle Saved InstantState) {// Some Code: MPM = (Power Manager) getActivity () GetSystemService (EventPOWER_SERVICE); If (MPM == empty) {Log.e (TAG, "PowerManager is empty"); } {MPartialWakeLock = mPM.NewWakeLock (PowerManager.PARTIAL_WAKE_LOCK, "LOG") Try it; MPartialWakeLock.aquire (); } Hold (exception e) {Log.i (TAG, "mPM.newWakeLock () EXCEPTION =" + e.toString ());}   

The problem occurs when the screen is off The application has been stopped, the application has been stopped.

I am currently using the following partial wake lock in an application: spreads my_frag fragment of public square {WakeLock wl; // change, config changes, public view creatives (layoutInflator Inflator, View Group container, bundle savedinstenstate) etc. {Set Written Instances (true); PowerManager pm = (PowerManager) this.getActivity (). GetSystemService (Context.POWER_SERVICE); Wl = pm.newWakeLock (PowerManager.PARTIAL_WAKE_LOCK, "MyWakeLock"); // I have to put it in a button click event based on an encyclical Task // (Side note: I should probably use a loader for my ACIS work but it also works) // Just click it button Take out if you do not need it (s.name ()), so there is no need to connect button here. Click on the button (see the new OnClickListener () {public void onClick (see v) {if (metrics_task! = Null) {status s = metrics_task.getStatus (); equals ("running") {if (metrics_task.running } {Metrics_task.cancel (true); Connect Button. Set Text ("Start"); Metrics_task.running = false; Wl.release (); & Lt; - Issues async stop} else {metrics_task = new start_metrics (ae); Metrics_task.execute (); Wl.acquire (); & Lt; - It starts at async startup}} and {metrics_task = new start_metrics (ae); Metrics_task.execute ();}} other {metrics_task = new start_metrics (ae); Metrics_task.execute ();}}});

Just remember to leave it when you are not using it

No comments:

Post a Comment