从登录到应用程序的一个小时后,我想显示一个警报,警告说他的会话将过期,然后我想将他记录在五分钟之后。用户可以处于应用程序的任何activitive中。没有活动的最佳方法是什么,他目前是一个问题。
我已经完成的工作是在他登录并使用Ontick和onfinsh方法处理这些事件后立即设置了一个倒计时数,我使用吐司来显示消息。我认为这不是最好的做法。您有更好的解决方案吗?
有两种方法可以在您的用户登录时实现此启动服务到达,然后在系统托盘中显示 NOTIFIFY ,单击该将启动待处理 interent ,您还可以在其中实现Logout Logic的其余部分。这是创建通知
的简单示例 // 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());
在这里阅读有关通知的更多信息
或者您可以使用Special 许可请求创建一个浮动窗口。您必须从系统中获得,否则您将无法创建浮动窗口也称为覆盖层。
这是一个完整的教程,但不建议采用这种方法,因此我建议您使用通知。