2017-12-13 26 views
0

앱에 로그인 한 후 사용자에게 자신의 세션이 만료되고 5 분 후에 내가 원하는 경고를 표시하고 싶습니다. 그를 로그 아웃하십시오. 사용자는 앱을 사용하고있을 수 있습니다. 그가 현재 활동하고있는 활동이없는 가장 좋은 방법은 무엇인가.경고 표시 앱의 어느 특정 시간 이후에 특정 시간이 지나면 로그 아웃하고 로그 아웃합니다.

로그인 한 직후에 countDownTimer를 설정하고 onTick 및 onFinsh 메서드를 사용하여 이러한 이벤트를 처리하고 토스트를 사용하여 메시지를 표시합니다. 나는 이것이 최선의 방법이라고 생각하지 않는다. 더 나은 해결책이 있습니까?

답변

0

이 그가 시작됩니다에 시스템 트레이 클릭에 통지를 표시하여 사용자 로그인으로 서비스를 시작하고 지정된 시간 후 도달 할 때까지에 카운터을 유지 당신이 달성 할 수있는 방법은 두 가지가 있습니다 보류중인 의도 나머지 로그 아웃 논리도 구현할 수 있습니다. 여기

// Instantiate a Builder object. 
NotificationCompat.Builder builder = new NotificationCompat.Builder(this); 
// Creates an Intent for the Activity 
Intent notifyIntent = 
     new Intent(new ComponentName(this, ResultActivity.class)); 
// Sets the Activity to start in a new, empty task 
notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | 
     Intent.FLAG_ACTIVITY_CLEAR_TASK); 
// Creates the PendingIntent 
PendingIntent pendingIntent = 
     PendingIntent.getActivity(
     this, 
     0, 
     notifyIntent, 
     PendingIntent.FLAG_UPDATE_CURRENT 
); 

// Puts the PendingIntent into the notification builder 
builder.setContentIntent(pendingIntent); 
// Notifications are issued by sending them to the 
// NotificationManager system service. 
NotificationManager mNotificationManager = 
    (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
// Builds an anonymous Notification object from the builder, and 
// passes it to the NotificationManager 
mNotificationManager.notify(id, builder.build()); 

이 알림

또는 특수 허가를 요청에 부동 창을 만들 수 있습니다에 대한 here 자세한 내용을 통지를 만드는 간단한 예입니다. 시스템에서 가져와야하는 경우 부동 창 (오버레이이라고도 함)을 만들 수 없습니다.

Here에 대한 전체 자습서이지만이 방법은 권장되지 않으므로 알려 주시면 좋습니다.