Retrieve an activity after Time out warning notification

孤街醉人 提交于 2019-11-29 12:16:12
Hamid

Finally I figured out the solution. There is no way to save the state of WebView and have all of the content, so we need to prevent reloading or recreating the webView. In order to have one instance of our activity that contains webView we should add the following code to our Manifest file:

<activity ...
        android:launchMode="singleInstance"
        android:alwaysRetainTaskState="true">

Then if through your application you needed to recreate the instance entirely to refresh the webView, you can use finish(); if it's inside of the activity or if you are in another activity and you want to recreate your webView activity, read this link to do it.

First of all, you should use the AlarmManager to trigger your notification from a Service.

Intent intent = new Intent(context, YourNotifService.class);
PendingIntent pendingService = PendingIntent.getService(context, 0, intent, 0);
AlarmManager alarm = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
long triggerTime =  SystemClock.elapsedRealtime()  + (5 * 60 * 1000);
alarm.set(AlarmManager.ELAPSED_REALTIME, triggerTime, pendingService);

About saving the complete state of your Activity, that's really up to you to go through each View and save the state. Best way would be to save it in a specific file and not in the SharedPreferences, but both could work.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!