2
사용자가 화면을 터치하면 앱이 종료됩니다. 이를 위해, onTouch() 메소드 나는 FinActivity 클래스는이 하나입니다화면이 꺼져있을 때 앱 다시 시작
Intent intent = new Intent(getBaseContext(), FinActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();
있습니다
나는 화면이 꺼져있을 때 내 응용 프로그램을 다시 시작하겠습니다public class FinActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
BroadcastReceiver mReceiver = new AlarmReceiver();
registerReceiver(mReceiver, filter);
Intent intent = new Intent(this, AlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(
this.getApplicationContext(), 234324243, intent, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
System.currentTimeMillis() + (60 * 1000),
System.currentTimeMillis() + (60 * 1000), pendingIntent);
finish();
}
. 나는이 AlarmReceiver 클래스가 :
public class AlarmReceiver extends BroadcastReceiver {
public static boolean wasScreenOn = true;
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
// do whatever you need to do here
System.out.println("Screen OFF");
wasScreenOn = false;
Intent i = new Intent(context, SplashScreen.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
} else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
// and do whatever you need to do here
System.out.println("Screen ONN");
wasScreenOn = true;
}
}
}
하지만이 줄에서 NullPointerException이 얻을 60 초 동안 내 실수 intent.getAction().equals(Intent.ACTION_SCREEN_OFF)
입니까? 내가 뭘 잘못 했니?
미리 감사드립니다.
null을 '인 텐트'로 확인하고 무시하면 제대로 작동합니까? – Glitch
if 조건없이 앱을 다시 시작하십시오. – Gabrielle