Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect App inactivity/idle timeout in NativeScript #5423

Closed
atchakraborty opened this issue Feb 15, 2018 · 6 comments
Closed

Detect App inactivity/idle timeout in NativeScript #5423

atchakraborty opened this issue Feb 15, 2018 · 6 comments

Comments

@atchakraborty
Copy link

atchakraborty commented Feb 15, 2018

I need to detect user's inactivity time in NativeScript app. I tried with few plugins (like ng-idle) but they are not compatible with NativeScript. I also tried to to emit application level event (in page router outlet) but it is not working either. Any help will be appreciated.

Infact I tried to extend activity, onPause, onResume everything is calling except onUserInteraction

public onUserInteraction(): void { console.log("onUserInteraction overwritten from app.ts"); // OVERWRITTEN BEHAVIOUR }

This piece of code never getting called.

Yes I have declared @JavaProxy('com.tns.NativeScriptActivity') and I have used tns-platform-declarations as well.

Please let me know what else to do?

@tsonevn tsonevn self-assigned this Feb 15, 2018
@tsonevn
Copy link
Contributor

tsonevn commented Feb 15, 2018

HI @atchakraborty,
In your case, you could try using the nativescript-idle plugin and check if it will work for your project.

@tsonevn tsonevn removed their assignment Feb 15, 2018
@atchakraborty
Copy link
Author

@tsonevn already used but its not giving me any option to check user interactivity or idle time. The only function is there for long waiting task. any other help?

@NickIliev
Copy link
Contributor

@atchakraborty the repository is for logging issues, bugs and features related to NativeScript.
For how-to related questions please use the community channels like the NativeScript forum, SO or NativeScript community slack

I have updated my sample with overwritten onUserInteraction method - the updated example can be found here.
The demo is very basic - keep in mind that you would like to extend the activity in a separate file and provide your own activity name (more details here).
Instruction regarding the demo can be found here

Closing as duplicate to https://stackoverflow.com/questions/48788676/detect-app-inactivity-idle-timeout-in-nativescript

@ghost ghost removed the question label Feb 16, 2018
@nikoTM
Copy link

nikoTM commented Sep 11, 2018

@NickIliev After extending the application like that other event callbacks stopped firing within the app:

    app.on(app.suspendEvent, () => {
      console.log('suspended');
    });

    app.on(app.resumeEvent, () => {
      console.log('resumed');
    });

Those callbacks never log. Is that expected behavior? If not, how can I fix it? Also, is it possible to somehow expose onUserInteraction events to be used within the app through the same event system as in app.on('userInteraction'... ? Currently to get hold of that event I need to create an observable outside of Angular app, create and push that event through that observable to get hold of it within ng app. This feels like a bad solution to me. Thanks.

EDIT:

Actually, I was able to get the callbacks to work using:

  app.android.on(app.AndroidApplication.activityPausedEvent, callback)
  app.android.on(app.AndroidApplication.activityResumedEvent, callback)

I guess my question is would it be possible to get hold of userInteraction event more elegantly than the custom solution mentioned above.

@s-doddapaneni
Copy link

How to achieve this for iOS using NativeScript and Angular?

@lock
Copy link

lock bot commented Jan 24, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked and limited conversation to collaborators Jan 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants