Native interface not work after AlarmManager/onReceive in Android 6.0

123 views
Skip to first unread message

ahs...@gmail.com

unread,
Jul 5, 2016, 4:28:45 AM7/5/16
to CodenameOne Discussions
Dear Sir,

On Android 6.0 when I wanna do AlarmManager and onReceive, it is quickly found out that of the Doze mode issue, the "setRepeating" is not work but using "setExactAndAllowWhileIdle"  instead ( or may use "setInexactRepeating") so that the receiving is successful. Afterwards when i call the native code function, the native code function is not work  anymore and the application will be suspended.

e.g.

After calling
public void setScheduler(Context context) {
//.................
        am.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pi);
//.................
}

Then
public void onReceive(Context context, Intent intent) {
//...............

Intent mainUIIntent = new Intent(context, MainUIStub.class);
mainUIIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mainUIIntent.putExtra(LAUNCH_BY_SCHEDULER, true);
context.startActivity(mainUIIntent);
//.................

}

Then in MainUI
public void start() {
//.................
MobileNative mobileNative = (MobileNative) NativeLookup.create(MobileNative.class);
if (mobileNative.isLaunchByScheduler()) {
Form gui = stateMachine.showForm("FormMain", null);
gui.getMenuBar().removeAll();
}
//.....................
}

When i call the native function "mobileNative.isLaunchByScheduler()" which is used to just return true, i can see it can go into the native function but cannot return and the application is suspend here.

Would you have any suggestion and what is the codename one response for the android 6.0 change for Doze mode issue?

Thanks and Regards,
Ronald

ahs...@gmail.com

unread,
Jul 5, 2016, 9:57:38 PM7/5/16
to CodenameOne Discussions, ahs...@gmail.com
any ideas? Many thanks!

Shai Almog

unread,
Jul 6, 2016, 1:35:50 AM7/6/16
to CodenameOne Discussions, ahs...@gmail.com
You shouldn't use your own activity or implement/extend additional classes in the native interface itself. We already have a portable way for background notifications so it's unclear to me what you are trying to achieve with native interfaces here?

ahs...@gmail.com

unread,
Jul 6, 2016, 1:52:04 AM7/6/16
to CodenameOne Discussions, ahs...@gmail.com
As the code presented, we would like to set a schedule at which time to start the application. Once the application start, it checks something from native function e.g. permission, get intent value. However, after the alarm manager trigger app start, all the native function call is no return success and app suspend. I have tried the app which was running smooth if i commented out all the native function call.

ahs...@gmail.com

unread,
Jul 6, 2016, 11:46:27 PM7/6/16
to CodenameOne Discussions, ahs...@gmail.com
Any updates? Thanks!

Shai Almog

unread,
Jul 7, 2016, 12:23:22 AM7/7/16
to CodenameOne Discussions, ahs...@gmail.com
Did you set the API level to a newer API level to work with this?
Maybe Chen has an idea here.

ahs...@gmail.com

unread,
Jul 7, 2016, 10:28:30 PM7/7/16
to CodenameOne Discussions, ahs...@gmail.com
Already using android api 23. Please help to check up the problem, many thanks!

zeus...@yahoo.com.hk

unread,
Jul 11, 2016, 10:23:40 PM7/11/16
to CodenameOne Discussions, ahs...@gmail.com
Any news? Thanks!

Shai Almog

unread,
Jul 12, 2016, 12:14:32 AM7/12/16
to CodenameOne Discussions, ahs...@gmail.com, zeus...@yahoo.com.hk
I assigned this to Chen but he's under a bit of a heavy load with a few enterprise customers and hasn't been as responsive lately. I pinged him again.

mispro...@gmail.com

unread,
Jul 13, 2016, 5:25:55 AM7/13/16
to CodenameOne Discussions, ahs...@gmail.com, zeus...@yahoo.com.hk
I see. Would you have another assignment if he is quite busy? Thanks and Regards!

Chen Fishbein

unread,
Jul 13, 2016, 12:05:21 PM7/13/16
to CodenameOne Discussions, ahs...@gmail.com, zeus...@yahoo.com.hk, mispro...@gmail.com
Are you seeing an exception in the android ddms log? can you open an issue with a test case? and I'll have a look

mispro...@gmail.com

unread,
Jul 13, 2016, 9:41:29 PM7/13/16
to CodenameOne Discussions, ahs...@gmail.com, zeus...@yahoo.com.hk, mispro...@gmail.com
 Hi, thank you for your response. I can't see any error log , it just stop once the native interface call after schedule kick start. What test case exactly do you want? Thanks and Regards!

Shai Almog

unread,
Jul 14, 2016, 1:32:23 AM7/14/16
to CodenameOne Discussions, ahs...@gmail.com, zeus...@yahoo.com.hk, mispro...@gmail.com
Create a hello world application and add to it code that reproduces the problem so we can reproduce it on our builds. Submit it based on the guidelines here: https://www.codenameone.com/blog/issue-submission-guideline.html

jsa4...@gmail.com

unread,
Aug 20, 2016, 11:43:05 PM8/20/16
to CodenameOne Discussions, ahs...@gmail.com
Is there a way to make native code consume less battery?

WhileIdle runs even while in low-power standby mode.

Shai Almog

unread,
Aug 21, 2016, 1:37:37 AM8/21/16
to CodenameOne Discussions, ahs...@gmail.com, jsa4...@gmail.com
I suggest opening a separate question for this as it is unrelated.
Reply all
Reply to author
Forward
0 new messages