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

Context.startForegroundService() did not then call Service.startForeground #8

Open
deckameron opened this issue May 13, 2019 · 11 comments
Assignees
Labels
help wanted Extra attention is needed

Comments

@deckameron
Copy link
Owner

[ERROR] :  TiExceptionHandler: (main) [9051,29263]
Context.startForegroundService() did not then call Service.startForeground()
[ERROR] :  TiExceptionHandler:
[ERROR] :  TiExceptionHandler:
android.app.ActivityThread$H.handleMessage(ActivityThread.java:2204)
[ERROR] :  TiExceptionHandler:
android.os.Handler.dispatchMessage(Handler.java:108)
[ERROR] :  TiExceptionHandler:     android.os.Looper.loop(Looper.java:166)
[ERROR] :  TiExceptionHandler:
android.app.ActivityThread.main(ActivityThread.java:7529)
[ERROR] :  TiExceptionHandler:     java.lang.reflect.Method.invoke(Native
Method)
[ERROR] :  TiExceptionHandler:
com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
[ERROR] :  TiExceptionHandler:
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)

It is an Android issue! Checkout here.

@deckameron deckameron added the help wanted Extra attention is needed label May 13, 2019
@deckameron deckameron self-assigned this May 13, 2019
@deckameron
Copy link
Owner Author

Hello @AppWerft!
Do you know any solution for this issue?
Thank you!

@m1ga
Copy link
Contributor

m1ga commented Jan 22, 2020

Any info here? Just had this error with a HUAWEI phone. But on a Pixel 4 it is working fine. Looking at the Android issue it looks like it has to do with initialization order of the service

@deckameron
Copy link
Owner Author

deckameron commented Jan 22, 2020

Hi @m1ga,
I haven't worked on the module for a while, so I will go back to it and try again.
Thank you for the tip regarding the initialization order of the service!
If you find any other information about this issue, please let me know. :-)

@m1ga
Copy link
Contributor

m1ga commented Jan 22, 2020

It was mentioned in the linked ticket somewhere. But I didn't try it yet. I'll have a look at the module, too.

@deckameron
Copy link
Owner Author

deckameron commented Jan 22, 2020

This is the way! :-)
I will have to refactor a lot my code to get this working. I will give it a try.

deckameron pushed a commit that referenced this issue Jan 22, 2020
@deckameron
Copy link
Owner Author

@m1ga Could you please test this version?
Let me know if the crash stops on the HUAWEI.

@m1ga
Copy link
Contributor

m1ga commented Jan 22, 2020

now my phones (Samsung A5 Android 8) and Pixel 4 (Android 10) stop with this error:

[ERROR] TiExceptionHandler: (main) [23,4267] Unable to start receiver ti.android.geofence.GeofenceBroadcastReceiver: java.lang.IllegalArgumentException: No such service ComponentInfo{com.test.geo/ti.android.geofence.JavascriptService}
[ERROR] TiExceptionHandler:
[ERROR] TiExceptionHandler:     android.os.Parcel.readException(Parcel.java:1971)
[ERROR] TiExceptionHandler:     android.os.Parcel.readException(Parcel.java:1913)
[ERROR] TiExceptionHandler:     android.app.job.IJobScheduler$Stub$Proxy.enqueue(IJobScheduler.java:211)
[ERROR] TiExceptionHandler:     android.app.JobSchedulerImpl.enqueue(JobSchedulerImpl.java:53)
[ERROR] TiExceptionHandler:     android.support.v4.app.JobIntentService$JobWorkEnqueuer.enqueueWork(JobIntentService.java:342)
[ERROR] TiExceptionHandler:     android.support.v4.app.JobIntentService.enqueueWork(JobIntentService.java:522)
[ERROR] TiExceptionHandler:     android.support.v4.app.JobIntentService.enqueueWork(JobIntentService.java:500)
[ERROR] TiExceptionHandler:     ti.android.geofence.JavascriptService.enqueueWork(JavascriptService.java:24)
[ERROR] TiExceptionHandler:     ti.android.geofence.GeofenceBroadcastReceiver.onReceive(GeofenceBroadcastReceiver.java:28)
[ERROR] TiExceptionHandler:     android.app.ActivityThread.handleReceiver(ActivityThread.java:3392)
[ERROR] TiExceptionHandler:     android.app.ActivityThread.-wrap18(Unknown Source:0)
[ERROR] TiExceptionHandler:     android.app.ActivityThread$H.handleMessage(ActivityThread.java:1780)
[ERROR] TiExceptionHandler:     android.os.Handler.dispatchMessage(Handler.java:105)
[ERROR] TiExceptionHandler:     android.os.Looper.loop(Looper.java:164)
[ERROR] TiExceptionHandler:     android.app.ActivityThread.main(ActivityThread.java:6944)
[ERROR] TiExceptionHandler:     java.lang.reflect.Method.invoke(Native Method)
[ERROR] TiExceptionHandler:     com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
[ERROR] TiExceptionHandler:     com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)

@m1ga
Copy link
Contributor

m1ga commented Jan 22, 2020

https://stackoverflow.com/a/49418249/5193915

Your app will crash if you call Context.startForegroundService(...) and then call Context.stopService(...) before Service.startForeground(...) is called.

not tested yet. Will check it at the weekend

@deckameron
Copy link
Owner Author

Thank you @m1ga ! Your help is greatly appreciated.

deckameron pushed a commit that referenced this issue Jan 23, 2020
@deckameron
Copy link
Owner Author

deckameron commented Jan 23, 2020

Hi @m1ga! I managed to get it working on my Pixel with Android 10.
I have uploaded a newer version. Please, feel free to give it a try whenever possible. :-)

@m1ga
Copy link
Contributor

m1ga commented Jan 23, 2020

it still crashes for me after 15 secs:

[INFO]  entered
[INFO]  JavascriptService: Service Started
[WARN]  TiJSIntervalService: (main) [1,5373] The intent is missing the extra value 'interval', therefore the code will be executed only once.
[INFO]  IT WORKED! It is a service
[INFO]  @@@ Service started.
[INFO]  id region1
[INFO]  trigger from service
[INFO]  GeofenceModule: (AsyncTask #1) [5,5378] Unable to find image [null] from assets.
[INFO]  I/com.test.geo: Thread[6,tid=22279,WaitingInMainSignalCatcherLoop,Thread*=0x784cc37000,peer=0x14240220,"Signal Catcher"]: reacting to signal 3
[INFO]  I/com.test.geo:
[INFO]  I/com.test.geo: Wrote stack traces to tombstoned
[DEBUG] AndroidRuntime: Shutting down VM
[ERROR] TiExceptionHandler: (main) [14885,20263] Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{bbaff86 u0 com.test.geo/.MyServiceService}
[ERROR] TiExceptionHandler:
[ERROR] TiExceptionHandler:     android.app.ActivityThread$H.handleMessage(ActivityThread.java:1945)
[ERROR] TiExceptionHandler:     android.os.Handler.dispatchMessage(Handler.java:107)
[ERROR] TiExceptionHandler:     android.os.Looper.loop(Looper.java:214)
[ERROR] TiExceptionHandler:     android.app.ActivityThread.main(ActivityThread.java:7356)
[ERROR] TiExceptionHandler:     java.lang.reflect.Method.invoke(Native Method)
[ERROR] TiExceptionHandler:     com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
[ERROR] TiExceptionHandler:     com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

it will fire once for my current fence and it will show the trigger from service from the attached service. But if I wait 15 secs and do nothing (not chanigng my location) it will crash

var geofence = require("ti.android.geofence");

function addFences() {
	geofence.addGeofences({
		clearExistingFences: true,
		fences: [{
			"id": "region1",
			latitude: xxxx,
			longitude: xxxx,
			"radius": 100,
			"transitions": [
				geofence.GEOFENCE_TRANSITION_ENTER
			],
			"title": "region1",
			"sound": "notification",
			"accentColor": "#E65100",
			"type": geofence.TYPE_PLACE_FENCE
		}],
		service: "com.test.geo.MyServiceService"
	});

	geofence.addEventListener(geofence.ERROR, function(e) {
		Ti.API.error(e.message);
	});

	geofence.addEventListener(geofence.ENTERED, function(e) {
		console.log("entered");
	});

	geofence.addEventListener(geofence.EXITED, function(e) {
		console.log("exited");
	});

	geofence.addEventListener(geofence.DWELL, function(e) {
		console.log("dwell");
	});

	geofence.addEventListener(geofence.STARTED_MONITORING, function(e) {
		console.log("start");
	});
}


function onOpen(e) {
	if (!Ti.Geolocation.hasLocationPermissions(Ti.Geolocation.AUTHORIZATION_ALWAYS)) {
		Ti.Geolocation.requestLocationPermissions(Ti.Geolocation.AUTHORIZATION_ALWAYS, function(e) {
			if (!e.success) {
				return;
			}
			console.log("got permission");
			addFences();
		});
	} else {
		console.log("got permission");
		addFences();
	}
}

function onClick(e) {
	geofence.startMonitoring();
}
function onClose(e){}
$.index.open();
<Alloy>
	<Window class="container" onOpen="onOpen">
		<Button id="btn" title="run" onClick="onClick"/>
	</Window>
</Alloy>

Edit:
I've added a log inside onStartCommand and it looks like that it is not called at all.

deckameron pushed a commit that referenced this issue Jan 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants