정기적으로 서버에 몇 가지 플래그가 있는지 확인하는 응용 프로그램이 있습니다. 그런 다음이 플래그의 값에 따라 메시지를 표시합니다.응용 프로그램의 현재 상태를 가져 오는 방법이 있습니까?
메시지를 표시하고 싶지 않은데 응용 프로그램이 앞에 있지 않습니다. 그리고 SharedPreferences를 사용하여 응용 프로그램 상태를 수동으로 저장합니다. 각 활동에서 내가 좋아하는 일을 수행합니다
@Override
protected void onStart() {
super.onStart();
SharedPreferences.Editor prefs = context.getSharedPreferences("myprefs", getApplicationContext().MODE_PRIVATE).edit();
prefs.putBoolean("appInFront", true);
prefs.commit();
}
@Override
protected void onPause() {
super.onPause();
SharedPreferences.Editor prefs = context.getSharedPreferences("myprefs", getApplicationContext().MODE_PRIVATE).edit();
prefs.putBoolean("appInFront", false);
prefs.commit();
}
을 그리고이 날 "appInFront"환경 설정에서 응용 프로그램의 상태를 얻을 수 있습니다 :
SharedPreferences prefs = context.getSharedPreferences("myprefs", Context.MODE_PRIVATE);
boolean appInFront = prefs.getBoolean("appInFront", true);
그러나 될 수있다 네이티브 메소드 또는 얻을 수있는 방법이 존재 응용 프로그램의 현재 상태 (앞에있는 응용 프로그램입니까, 아니면 배경에 있습니까?)
SDK 샘플의 ApiDemos/app/AlarmController와 같이 BroadcastReceiver에서 Toast Notifications를 사용하고 있습니다. – Serg
감사합니다. Herrmann, 저렇게 했어요. – Serg
왜 onResume 메서드에 super.onStart()가 있습니까? – maysi