Android unable to start service intent has extras

java.lang.RuntimeException: Unable to start service with intent has extras android.os.NetworkOnMainThreadException

This is my first post here, and I hope I do it well.

I’m trying to edit an Open Source Updater (YAOS Updater), and when I try to connect, it gives me an error.

I’ll try to explain the better I can.

I’ve added a value in the JSON used to list all the files. the new value of each file is urlArchivo, which contains the complete url of the file.

This is the part of the code:

The variable urlArchivo, in the logcat, gets the right URL, I mean, the

Returns the correct complete url of the file, but it FC, showing the next logcat

I hope I’ve posted all the information needed to solve this problem. If any more information is needed, please let me know!

1 Answer 1

Android throws android.os.NetworkOnMainThreadException because.

The exception that is thrown when an application attempts to perform a networking operation on its main thread.

This is only thrown for applications targeting the Honeycomb SDK or higher. Applications targeting earlier SDK versions are allowed to do networking on their main event loop threads, but it’s heavily discouraged.

Create a separate thread for your networking operations, it’s telling you that basically.

Potentially long running operations such as network or database operations, or computationally expensive calculations such as resizing bitmaps should be done in a child thread

Note that services, like other application objects, run in the main thread of their hosting process. This means that, if your service is going to do any CPU intensive (such as MP3 playback) or blocking (such as networking) operations, it should spawn its own thread in which to do that work.

You could have investigated this by yourself, but eh — do it next time.

Источник

ActivityManager: Unable to start service Intent < act=com.google.android.c2dm.intent.RECEIVE flg=0x1000010 (has extras) >U=0: not found

Since trying to update my Android application from Eclipse over to Android Studio (converting to a gradle project) I’ve been running into issues. I think I’ve smoothed over most of them, but I am unable to get notifications from GCM (which is an important part of the application).

Here is the message I from the Android phone getting the GCM message (these messages are posted from a server multi casting to multiple android devices):

Читайте также:  Аналоги zbrush для андроид

Here’s my AndroidManifest.xml

I have also tried changing the to with the same results.

Basically what I can tell is that the Android device is getting the GCM message. And it knows that the GXM IntentService is my custom com.ddv.android.gcm.support.app.GCMIntentService, but it’s not doing anything with it. And it’s not really throwing any error. The message i see in the logcat just looks like a warning if anything.

I’ve made sure my GCMIntentService is in the main package of the application. And that I have all the correct permissions so I’m not sure what I’m missing or why I can’t get this to work.

I did have to change how my GCM registers when I updated my application and it’s possible I still have this incorrect. But the following code is not throwing any errors and when I send out the GCM message from the server all of my Android devices get the message from above (making it look like they are registered correctly and getting something from Google).

GCM registration code:

Oh right final piece of info. Here is what I am expecting for my application to do: in my GCMIntentService.java I’m expecting the overwritten onMessage() function to be called which displays an alert based on the GCM message received.

I know I’ll eventually have to update to FCM, but this should still be working in the mean time (till April 2019 when GCM gets completely removed).

Источник

Unable to start service Intent: not found

I’ve the same issue described here but i can’t understand whats wrong.

My issue is: Unable to start service Intent < act=.connections.MoodyService >U=0: not found

EDIT I’ve changed my package from connections to service in the source code, sorry for the confusion

My manifest.xml

service is the package and MoodyService is the class name

My service class

And in my main Intent.

and also tried

and tried with the full path

8 Answers 8

Solved

I deleted the period in the beginning of the package name in the manifest and it worked, in another words:

This doesn’t work:

But this does work:

And in the main:

But it goes against what is written in the documentation:

android:name The name of the Service subclass that implements the service. This should be a fully qualified class name (such as, «com.example.project.RoomService»). However, as a shorthand, if the first character of the name is a period (for example, «.RoomService»), it is appended to the package name specified in the element. Once you publish your application, you should not change this name (unless you’ve set android:exported=»false»).

There is no default. The name must be specified.

Читайте также:  Usb мышка для планшета android

Источник

Unable to start Service Intent

I have a service class. I have exported this class to jar and I have embed the jar in my client app.

When needed, I call the service class. When I try to do this, I get the following error:

I have other class apart from the service class, which I am able to access (create object of that class) which are inside the same jar.

I feel I have missed out some thing in my configuration or manifest or so.

Please help me identifying the same. My code is below:

Thanks in advance,
Vinay

6 Answers 6

For anyone else coming across this thread I had this issue and was pulling my hair out. I had the service declaration OUTSIDE of the ‘ ‘ end tag DUH!

RIGHT:

WRONG but still compiles without errors:

First, you do not need android:process=»:remote» , so please remove it, since all it will do is take up extra RAM for no benefit.

Second, since the element contains an action string, use it:

1) check if service declaration in manifest is nested in application tag

2) check if your service.java is in the same package or diff package as the activity

I hope I can help someone with this info as well: I moved my service class into another package and I fixed the references. The project was perfectly fine, BUT the service class could not be found by the activity.

By watching the log in logcat I noticed the warning about the issue: the activity could not find the service class, but the funny thing was that the package was incorrect, it contained a «/» char. The compiler was looking for

I moved the service class out from the package and back in and everything worked just fine.

In my case the 1 MB maximum cap for data transport by Intent. I’ll just use Cache or Storage.

I’ve found the same problem. I lost almost a day trying to start a service from OnClickListener method — outside the onCreate and after 1 day, I still failed. Very frustrating! I was looking at the sample example RemoteServiceController . Theirs works, but my implementation does not work!

The only way that was working for me, was from inside onCreate method. None of the other variants worked and believe me I’ve tried them all.

    If you put your service class in different package than the mainActivity, I’ll get all kind of errors
Читайте также:  Самый лучший android планшет

Also the one «/» couldn’t find path to the service, tried starting with Intent(package,className) and nothing , also other type of Intent starting

I moved the service class in the same package of the activity Final form that works

Hopefully this helps someone by defining the listerners onClick inside the onCreate method like this:

Also very important for the Manifest file, be sure that service is child of application:

Источник

Not allowed to start service Intent — Android Oreo

I am currently using the startWakefulService function which is crashing in Oreo. I realise I either have to switch to startForegroundService() and use a foreground service, or switch to JobIntentService but based on my code below I am not sure what to do. (Sorry I am an android novice). Any points in the right direction will be greatly appreciated.

This is the current error I get when run on Android 8.x

Fatal Exception: java.lang.RuntimeException Unable to start receiver com.heyjude.heyjudeapp.gcm.GcmBroadcastReceiver: java.lang.IllegalStateException: Not allowed to start service Intent < act=com.google.android.c2dm.intent.RECEIVE flg=0x1000010 pkg=com.app.app cmp=com.app.app/.gcm.GCMIntentService (has extras) >: app is in background uid UidRecord

2 Answers 2

I experience the same behaviour.

Why this issue happens?

Due to the new Background Execution Limits of Android 8 and you should not start services background.

How I fixed it

Migrate your GCMIntetService to JobIntentService instead of IntentService .

Please follow this steps: 1) Add the BIND_JOB_SERVICE permission to your service:

2) In your GCMIntentService , instead extending the IntentService , use android.support.v4.app.JobIntentService and override onHandleWork then remove the override in you onHandleIntent .

Then finally, in your GCMBroadcastReceiver , enqueue your GCMIntentService .

This implementation work for me after we update our target sdk to 27 and I hope it works for you.

As of Android O, background check restrictions make this class no longer generally useful. (It is generally not safe to start a service from the receipt of a broadcast, because you don’t have any guarantees that your app is in the foreground at this point and thus allowed to do so.) Instead, developers should use android.app.job.JobScheduler to schedule a job, and this does not require that the app hold a wake lock while doing so (the system will take care of holding a wake lock for the job).

Only alternative is to start a ForeGroundService or use JobScheduler/JobIntentService

You can start foreground service as follows:

You also need to call startService() from your Service class and display notification. You can follow my answer on this SO for implementation details.

Источник

Оцените статью