Im得到錯誤上下文和上下文。應該去那裏?Android上下文和上下文PowerManager
PowerManager mgr = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
WakeLock wakeLock = mgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakeLock");
wakeLock.acquire();
Im得到錯誤上下文和上下文。應該去那裏?Android上下文和上下文PowerManager
PowerManager mgr = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
WakeLock wakeLock = mgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakeLock");
wakeLock.acquire();
好,如果你正在做這個活動裏面,只是刪除context.
所以它應該是這樣的:PowerManager mgr = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager mgr = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
在上面的一行context
是活動的背景和在Context.POWER_SERVICE
Context
是具有靜態變量POWER_SERVICE
的類。請參閱this。
你的情況,如果要實現在你的活動驗證碼,然後不寫上下文,這樣你的代碼就會像下面
PowerManager mgr = (PowerManager) getSystemService(Context.POWER_SERVICE);
,如果你希望寫這行的活動之外,你需要編寫上下文。
與this
或getApplicationContext()
PowerManager的經理=(電源管理器)context.getSystemService(Context.POWER_SERVICE)更換context
;
與nameofclass.this更換環境,或使用的getContext()
它將工作
好了,你想怎麼辦,你得到了什麼錯誤? – Tim 2012-02-23 14:06:32