How to detect idle activity using angular nativescript and redirect to login screen


#1

I have downloaded the basic grocery app with login screen and then the grocery list page…

I want to add a timer of 12s which after finished will redirect the user to login screen again.

the timer will open up only after 20s of non intervention by user.

How can i achieve it using nativescript.


Detect user inactivity/idle (subclass UIApplication)
#2

Yyou could try using the nativescript-idle plugin(https://www.npmjs.com/package/nativescript-idle) and check if it will work for your project.


#3

Or you can extend the native application lifecycle as described here,


#4

thanks for such a quick response

actually i already visited this issue mentioned above but i couldn’t get it run in my project neither do i understand its implementation

I have created two files activity.android.ts and application.android.ts inside app folder as mentioned in the instruction present in nativescript

but it is throwing error [’ cannot find namespace ‘android’]

Please suggest


#5

the error has been resolved by adding reference path for android platform declaration inside refrences.d.ts file


#6

after doing the necssary changes mentioned in this link
i am not able to launch the application…It says ‘application has been stopped’

Logtrace:

Successfully synced application org.nativescript.groceries on device 015d4bdb1d23ee0d.
ActivityManager: Force stopping com.android.chrome appid=10030 user=-1: replace sys pkg
ActivityManager: Force finishing activity 3 ActivityRecord{2009b5f8 u0 com.android.chrome/com.google.android.apps.chrome.ChromeTabbedActivity t27}
ActivityManager: Process com.google.android.gms.ui (pid 19070) has died
ActivityManager: Force stopping com.android.chrome appid=10030 user=-1: update pkg
ActivityManager: Force stopping com.android.chrome appid=10030 user=0: pkg removed
ActivityManager: Start proc 19813:com.android.chrome/u0a30 for service com.android.chrome/com.google.ipc.invalidation.ticl.android2.channel.GcmRegistrationTaskService
ActivityManager: Waited long enough for: ServiceRecord{1324ce99 u0 com.google.android.apps.photos/com.google.android.libraries.social.async.BackgroundTaskService}
ActivityManager: Waited long enough for: ServiceRecord{1c598d79 u0 com.android.providers.downloads/.DownloadService}
ActivityManager: Force stopping com.google.android.tts appid=10050 user=-1: replace sys pkg
ActivityManager: Force stopping com.google.android.tts appid=10050 user=-1: update pkg
ActivityManager: Force stopping com.google.android.tts appid=10050 user=0: pkg removed
ActivityManager: Waited long enough for: ServiceRecord{18e99080 u0 com.google.android.apps.photos/com.google.android.libraries.social.async.BackgroundTaskService}


#7

Did you check the working example here, tried running that directly?


#8

ok…let me try once


#9

yes …it works…

but i want to create a timer which gets activated if the user remain inactive for 20s…
how will i achieve that


#10

Since you confirmed extending activity worked in the example project, it’s something wrong within your project please cross check.


#11

yes but in this example project also i don’t see the timer thing actually working…


#12

i am waiting for appropriate answer …
even in the stackoverflow issue link …the solution is provided for android studio…

i am looking for solution which can be achieved using angular nativescript.

Please suggest


#13

You already got access to onUserInteraction callback, use timer module - simple setTimeout / setInterval apis whichever is suitable for you.


#14

thanks for the response…let me try it


#15

sorry for late update…it worked for me perfectly fine…thanks :slight_smile:


#16

hey @kanchan, I already have the need to do this, were you using a ns-angular app? how did you manage to get a reference to the Router ouside the scope of the angular app from the overrdiden onUserInteraction method to do the navigation? Hope you can help me!


#17

yes i am working on angular nativescript app.

For android,
onUserInteraction method works but i did not try using navigation

I worked in ios but since in ios we cannot use onUserInteraction…so manually i have to keep track of tap event for each page

something like this;

app.component.html

<Page (id)="1" (Tap)="OnClick($event)">
<page-router-outlet>  </page-router-outlet>
</Page>

#18

On Android, what do you do inside onUserInteraction method?


#19

For iOS there seems to be an similar option by extending uiapplication.