2012-01-25 270 views
1

我想了解的是,屏幕是關閉的,當用戶在android.I鎖定的手機使用的廣播接收器像這樣和註冊,但我沒有得到屏幕關閉或不屏幕鎖定和解鎖

public class MyActivity extends Activity{ 

    private static final String ACTION = "android.intent.action.ACTION_SCREEN_OFF"; 
    BroadcastReceiver myReceiver; 
    Context context; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     super.onCreate(savedInstanceState); 
     context = this; 
     final IntentFilter theFilter = new IntentFilter(); 
     theFilter.addAction(ACTION); 

     context.registerReceiver(myReceiver, theFilter); 
     System.out.println("inside increate"); 
     myReceiver = new BroadcastReceiver(){ 

      @Override 
      public void onReceive(Context context, Intent intent) { 
       // TODO Auto-generated method stub  
        System.out.println("phone locked*****");     
      } 

     }; 

    }} 

如何找出這個問題?

+0

http://stackoverflow.com/questions/8968265/android-auto-logout-when-app-goes-to-background/8968763#8968763 –

回答

2

第1步:刪除private static final String ACTION

第2步:使用Intent.ACTION_SCREEN_OFFaddAction()線(或更好,但只是將其提供給IntentFilter構造和擺脫addAction()線)

第3步:使用android.util.Log代替System.out.println()

+0

大答案:): ) – Prasad