intentservice

Android IntentService can't instantiate class; no empty constructor

匿名 (未验证) 提交于 2019-12-03 08:33:39
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a MainActivity class that needs to access an online API (thus using network resources). This requires a background thread that I've created in a separate file HttpRequestService.java . MainActivity.java: public class MainActivity extends Activity { public static final String API_KEY = "KEYKEYKEYKEYKEY"; public static final String CLIENT_ID = "IDIDIDIDIDIDID"; private final String BROADCAST_ACTION = "com.example.BROADCAST"; private final String EXTENDED_DATA_STATUS = "com.example.STATUS"; static final String LOGCAT_TAG =

Prevent Android “process is bad” error

馋奶兔 提交于 2019-12-03 05:11:32
The process is bad error does not seem to be very well documented, and I have only been able to find workarounds. I am instead interested in the cause of this error and how to prevent it from happening, and not how to manually handle it through rebooting, relaunching app, etc. My particular application uses an AlarmManager to launch an IntentService which runs for ~10s every ~30s. This is called on creation of the application: Intent serviceIntent = new Intent(appContext, MyService.class); serviceIntent.putExtra("service_extra", extra); launchService = PendingIntent.getService( appContext,

What is the difference between service, intentService in android? [duplicate]

你说的曾经没有我的故事 提交于 2019-12-03 04:35:56
This question already has answers here : Service vs IntentService (11 answers) What is the difference between Service and an IntentService in Android? What is the difference between AsyncTask and an IntentService in Android? GVillani82 1. Difference between Service and IntentService Service : It is the base class for the Android services, that you can extend for creating any service. Since the service run inside the UI thread, it requires that you create a working thread for executing its work. IntentService : it is a subclass of Service , that simplifies your work. It works already in a

Android Oreo JobIntentService Keep running in background for Android 7 &below and crashing often in Android 8 & above

前提是你 提交于 2019-12-03 03:29:14
I have recently replaced all my service to foreground services and JobIntentService since there are some background execution limits ( https://developer.android.com/about/versions/oreo/background ) in oreo and above. As per documentation, JobIntentService acts like Intent Service for Android 7 & below and acts like JobScheduler for Android 8 & above. I have noticed there is an issue in new JobIntentService provided by Google. Android 8 & above: There is a crash happening continuously in android 8 and above. There was a ticket raised here mentioning about the same issue https://issuetracker

StartForeground for IntentService

匿名 (未验证) 提交于 2019-12-03 02:56:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have an IntentService and I want to make it sticky with an ongoing notification. The problem is that the notification appears and then disappears immediately. The service continues running. How should I use startForeground in an IntentService? @Override public int onStartCommand(Intent intent, int flags, int startId) { super.onStartCommand(intent, flags, startId); Notification notification = new Notification(R.drawable.marker, "Notification service is running", System.currentTimeMillis()); Intent notificationIntent = new Intent(this,

Android ServiceTestCase for IntentService

匿名 (未验证) 提交于 2019-12-03 02:16:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm currently writing unit tests for an android application and stumbled into the following issue: I use the ServiceTestCase to test an IntentService like this: @Override public void setUp() throws Exception { super.setUp(); } public void testService() { Intent intent = new Intent(getSystemContext(), MyIntentService.class); super.startService(intent); assertNotNull(getService()); } However I noticed that my IntentService is created (means that onCreate is called) but I never receive a call into onHandleIntent(Intent intent) Has anyone

How to stop intentservice in android?

匿名 (未验证) 提交于 2019-12-03 01:39:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: Could anyone tell me how to stop intentservice in Android? If I use stopservice to stop an intentservice, it doesn't work. I have browsed the website, but nobody has given a clear answer to this question. 回答1: Try calling stopSelf() from within the service. The documentation says that some processes may take a long time to complete, so your service is most likely waiting for them to stop. You should probably look into that. Once all requests are complete, the service stops itself. 回答2: The IntentService is built to stop itself when

Notification created by IntentService uses always a wrong Intent

倖福魔咒の 提交于 2019-12-03 01:14:53
Problem When the user presses Send "Button 1" (scroll down to see the construction of the app) a new Notification is created from the RefreshService . If the user presses this notification a MainActivity instance gets started and receives a String with the value Button 1 over the Intent . This value gets displayed. When the user presses now the Send "Button 2" a new Notification is created from the RefreshService . If the user presses this notification a MainActivity instance gets started and receives a String ALSO with the value Button 1 over the Intent . So as you can guess, normally there

Waiting for asynchronous callback in Android's IntentService

荒凉一梦 提交于 2019-12-03 01:10:30
I have an IntentService that starts an asynchronous task in another class and should then be waiting for the result. The problem is that the IntentService will finish as soon as the onHandleIntent(...) method has finished running, right? That means, normally, the IntentService will immediately shut down after starting the asynchronous task and will not be there anymore to receive the results. public class MyIntentService extends IntentService implements MyCallback { public MyIntentService() { super("MyIntentService"); } @Override protected final void onHandleIntent(Intent intent) {

Service

匿名 (未验证) 提交于 2019-12-03 00:30:01
Service service是一个可以在后台执行、长时间运行而不提供用户界面的应用组件,也可为其他应用提供一些功能接口。服务可由其他应用组件启动,而且即使用户切换到其他应用,服务仍将在后台继续运行。所谓的后台是相对前台而言的,具体就是说不依赖于用户界面。 service不是进程,不是线程。但service运行于所在进程的主线程,它有独立的生命周期。 下载文件,播放音乐,购买车票 等等 private static final String TAG = "servers" ; @Override public void onCreate () { super .onCreate(); Log.e(TAG, "onCreate: .................." ); } @Override public int onStartCommand ( final Intent intent, int flags, int startId) { new Thread( new Runnable() { int content= 0 ; String name=intent.getStringExtra( "name" ); @Override public void run () { while (content< 100 ){ try { Thread.sleep( 1000 );