1
votes

I am trying to use Hyperloop to use the isCurrentActivityInForeground method inside org.appcelerator.titanium.TiApplication

https://github.com/appcelerator/titanium_mobile/blob/master/android/titanium/src/java/org/appcelerator/titanium/TiApplication.java

I have tried the following and some other ways but I am unable to require the class - Any suggestions?

var TiApplicationClass = require('org.appcelerator.titanium.TiApplication');
var TiApplication = new TiApplicationClass;
var isInForeground = TiApplication.isCurrentActivityInForeground();

Ti.API.log("isInForeground");
Ti.API.log(isInForeground);

PS. I have asked in the slack channels multiple times but no help

2

2 Answers

1
votes

I think benCoding.Android.Tools module is what you need: https://github.com/benbahrenburg/benCoding.Android.Tools

if (OS_ANDROID) {
    var platformTools = require('bencoding.android.tools').createPlatform(),
        wasInForeGround = true;

    setInterval(function() {
        var isInForeground = platformTools.isInForeground();

        if (wasInForeGround !== isInForeground) {
            Ti.App.fireEvent(isInForeground ? 'resumed' : 'paused');

            wasInForeGround = isInForeground;
        }
    }, 3000);
}

Sample code credits to Fokke Zandbergen: http://www.tidev.io/2014/01/28/paused-resumed-events-on-android/

1
votes

The internal SDK classes are not accessible via Hyperloop so far. But I like the idea! Can you create a ticket the Appcelerator JIRA so it can be scheduled?