Permission Denial: startForeground requires android.permission.FOREGROUND_SERVICE

Lately we have suddenly been seeing a few of the following stack traces. Why could that be? This is from when the app tries to move an audio commentary service into the foreground with a media notification and everything. java.lang.SecurityException: Permission Denial: startForeground from pid=1824, uid=10479 requires android.permission.FOREGROUND_SERVICE at android.os.Parcel.createException(Parcel.java:1942) at android.os.Parcel.readException(Parcel.java:1910) at android.os.Parcel.readException(Parcel.java:1860) at … Read more

Android Fatal signal 11 (SIGSEGV) at 0x636f7d89 (code=1). How can it be tracked down?

I’ve been reading the other posts on tracking down the reasons for getting a SIGSEGV in an Android app. I plan to scour my app for possible NullPointers related to Canvas use, but my SIGSEGV barfs up a different memory address each time. Plus I’ve seen code=1 and code=2. If the memory address was 0x00000000, … Read more

Trying to start a service on boot on Android

I’ve been trying to start a service when a device boots up on android, but I cannot get it to work. I’ve looked at a number of links online but none of the code works. Am I forgetting something? AndroidManifest.xml <receiver android:name=”.StartServiceAtBootReceiver” android:enabled=”true” android:exported=”false” android:label=”StartServiceAtBootReceiver” > <intent-filter> <action android:name=”android.intent.action._BOOT_COMPLETED” /> </intent-filter> </receiver> <service android:name=”com.test.RunService” android:enabled=”true” … Read more

getApplication() vs. getApplicationContext()

I couldn’t find a satisfying answer to this, so here we go: what’s the deal with Activity/Service.getApplication() and Context.getApplicationContext()? In our application, both return the same object. In an ActivityTestCase however, mocking the application will make getApplication() come back with the mock, but getApplicationContext will still return a different context instance (one injected by Android). … Read more

Android 8.0: java.lang.IllegalStateException: Not allowed to start service Intent

On application launch, app starts the service that should to do some network task. After targeting API level 26, my application fails to start service on Android 8.0 on background. Caused by: java.lang.IllegalStateException: Not allowed to start service Intent { cmp=my.app.tt/com.my.service }: app is in background uid UidRecord{90372b1 u0a136 CEM idle procs:1 seq(0,0,0)} as I … Read more

Example: Communication between Activity and Service using Messaging

I couldn’t find any examples of how to send messages between an activity and a service, and I have spent far too many hours figuring this out. Here is an example project for others to reference. This example allows you to start or stop a service directly, and separately bind/unbind from the service. When the … Read more

Service vs IntentService in the Android platform

I am seeking an example of something that can be done with an IntentService that cannot be done with a Service (and vice-versa)? I also believe that an IntentService runs in a different thread and a Service does not. So, as far as I can see, starting a service within its own thread is like … Read more