2012-02-23 73 views
0

Im得到錯誤上下文上下文。應該去那裏?Android上下文和上下文PowerManager

PowerManager mgr = (PowerManager)context.getSystemService(Context.POWER_SERVICE); 
    WakeLock wakeLock = mgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakeLock"); 
    wakeLock.acquire(); 
+2

好了,你想怎麼辦,你得到了什麼錯誤? – Tim 2012-02-23 14:06:32

回答

0

好,如果你正在做這個活動裏面,只是刪除context.所以它應該是這樣的:PowerManager mgr = (PowerManager) getSystemService(Context.POWER_SERVICE);

0

PowerManager mgr = (PowerManager)context.getSystemService(Context.POWER_SERVICE);

在上面的一行context是活動的背景和在Context.POWER_SERVICEContext是具有靜態變量POWER_SERVICE的類。請參閱this

你的情況,如果要實現在你的活動驗證碼,然後不寫上下文,這樣你的代碼就會像下面

PowerManager mgr = (PowerManager) getSystemService(Context.POWER_SERVICE); 

,如果你希望寫這行的活動之外,你需要編寫上下文。

0

thisgetApplicationContext()

0

PowerManager的經理=(電源管理器)context.getSystemService(Context.POWER_SERVICE)更換context;

與nameofclass.this更換環境,或使用的getContext()

它將工作