package com.gyarmy.lockScreen; import android.os.Bundle; import android.app.Activity; import android.content.Intent; import android.content.IntentFilter; import android.view.Menu; public class MainActivity extends Activity { private ScreenActivity phoneScreen; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); phoneScreen = new ScreenActivity(); IntentFilter filter = new IntentFilter(); //intent.setAction("android.intent.action.SCREEN_OFF"); //intent.setAction("android.intent.action.SCREEN_ON"); filter.addAction("android.intent.action.SCREEN_OFF"); filter.addAction("android.intent.action.SCREEN_ON"); registerReceiver(phoneScreen, filter); } @Override protected void onDestroy() { // TODO Auto-generated method stub super.onDestroy(); unregisterReceiver(phoneScreen); } }
0则评论给“广播的注册和解除注册”