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


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)

Yyou could try using the nativescript-idle plugin( and check if it will work for your project.


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


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 and inside app folder as mentioned in the instruction present in nativescript

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

Please suggest


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


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


Successfully synced application org.nativescript.groceries on device 015d4bdb1d23ee0d.
ActivityManager: Force stopping appid=10030 user=-1: replace sys pkg
ActivityManager: Force finishing activity 3 ActivityRecord{2009b5f8 u0 t27}
ActivityManager: Process (pid 19070) has died
ActivityManager: Force stopping appid=10030 user=-1: update pkg
ActivityManager: Force stopping appid=10030 user=0: pkg removed
ActivityManager: Start proc for service
ActivityManager: Waited long enough for: ServiceRecord{1324ce99 u0}
ActivityManager: Waited long enough for: ServiceRecord{1c598d79 u0}
ActivityManager: Force stopping appid=10050 user=-1: replace sys pkg
ActivityManager: Force stopping appid=10050 user=-1: update pkg
ActivityManager: Force stopping appid=10050 user=0: pkg removed
ActivityManager: Waited long enough for: ServiceRecord{18e99080 u0}


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


ok…let me try once


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


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


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


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


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


thanks for the response…let me try it


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


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!


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;


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


On Android, what do you do inside onUserInteraction method?


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