intentservice

How to update ListView in Android after an IntentService returns something to an ResultReceiver

…衆ロ難τιáo~ 提交于 2019-12-24 03:17:13
问题 Perhaps the reason I can't find an answer to this, is that I'm doing the question the wrong way, but still I hope that here on SO someone can answer this. I have a MainActivity with a ListView that present some values - after processing - from a database: public class MainActivity extends Activity { ListView mainViewList; CTTObjectsArrayAdapter arrayAdapter; ArrayList<CTTObject> cttObjects = null; public UpdateObjectResultReceiver updateObjectReceiver; @Override protected void onCreate(Bundle

android downloading multiple files with InputStream FileOutputStream

╄→гoц情女王★ 提交于 2019-12-24 01:45:11
问题 So I have an app which downloads certain files, dedicated to a client of mine who is hosting his files on a remote location, and i'm doing so using the code below: public class DownloadService extends IntentService { private int result = Activity.RESULT_CANCELED; public DownloadService() { super("DownloadService"); } @Override protected void onHandleIntent(Intent intent) { String urlPath = intent.getStringExtra(URL); String fileName = intent.getStringExtra(FILENAME); File output = new File

Android GCM Sending token to server

北城余情 提交于 2019-12-24 01:38:07
问题 The GCM Sample Project gives a stubbed out example of sending a GCM token to your server: public class RegistrationIntentService extends IntentService { ... @Override protected void onHandleIntent(Intent intent) { try { ... String token = instanceID.getToken(getString(R.string.gcm_defaultSenderId), GoogleCloudMessaging.INSTANCE_ID_SCOPE, null); Log.i(TAG, "GCM Registration Token: " + token); // TODO: Implement this method to send any registration to your app's servers.

How to verify IntentService start

隐身守侯 提交于 2019-12-23 09:26:38
问题 I'm trying to test my app behavior with Espresso-2.2 On main activity, when button pressed both service and another activity is being started: public class MainActivity extends Activity { public void onButtonClicked() { startActivity(SecondActivity.getStartIntent()); startService(MyIntentService.getStartIntent()); } } I'm testing if intended components are being started: public class MainActivityTest { @Rule public final IntentsTestRule<MainActivity> intentsRule = new IntentsTestRule<>

Service or IntentService or AlarmManager approach

天大地大妈咪最大 提交于 2019-12-22 09:58:38
问题 I am building a game-like application and I've been reading about all the different approaches of running things with Services in background, foreground, Alarms and so on, and I am a bit confused. My app would go like this (example): user presses a button in Main, then he can close the app after 30 minutes Activity1 opens up user finishes whatever he needs to do in that activity, which triggers the next activity to start after 2 hours after 2 hours Activity2 opens up user finishes whatever he

Does AlarmManager require the PendingIntent to be of Type BroadcastReceiver?

眉间皱痕 提交于 2019-12-22 09:24:21
问题 The documentation for AlarmManager seems to imply (but does not outright explicitly require) that the PendingIntent you pass in to any of the set() methods should be of the type BroadcastReceiver, but I tested passing in other component types (like an IntentService) and it seemed to work fine. Is it safe to use non-BroadcastReceiver Intents with AlarmManager? 回答1: Yes, and it has always worked, but I suspect not in the way that you're thinking. You can use any PendingIntent with an alarm;

How to check if an IntentService was started

眉间皱痕 提交于 2019-12-22 08:59:46
问题 I'd like to get to know if an Activity successfully started an IntentService . As it's possible to bind an IntentService via bindService() to keep it running, perhaps an approach would be to check if invoking startService(intent) results in a call of onStartCommand(..) or onHandleIntent(..) in the service object. But how can I check that in the Activity? 回答1: I'd like to get to know if an Activity successfully started an IntentService. If you don't get an exception in either the activity or

Should onHandleIntent be called when IntentService is started with bindService?

喜欢而已 提交于 2019-12-21 18:56:09
问题 My service extends IntentService and when it is started with startService , onHandleIntent gets called. However, when the service is started with bindService (I do need binding), onHandleIntent does not get called. Should onHandleIntent be called when IntentService is started with bindService ? Is startService the only way IntentService should be started? The documentation for IntentService says the following: Clients send requests through startService(Intent) calls; the service is started as

Capturing IntentService Intents before onHandleIntent

喜欢而已 提交于 2019-12-21 12:38:04
问题 I have an IntentService which queues up web service calls to be made. I pass an integer as an Extra with each Intent which defines the type of web service call to be made. I'd like to create a situation where, if an Intent to perform a particular web service is passed to the IntentService and an Intent for that same web service already exists in the IntentService queue, the Intent is not processed. Ideally, I'd throw away the Intent, but I could also add an Extra to it that lets the code know

Android中线程和线程池

江枫思渺然 提交于 2019-12-21 05:10:55
我们知道线程是CPU调度的最小单位。在Android中主线程是不能够做耗时操作的,子线程是不能够更新UI的。在Android中,除了Thread外,扮演线程的角色有很多,如AsyncTask,IntentService和HandlerThread等等。由于内容过多,所以将分为上下两部分,第一部分主要和大家谈谈Android中的线程,以及在Android中的常用的线程池。第二部分我们一起来了解一下AsyncTask的使用和工作原理。 1、HandlerThread HandlerThread是Thread的子类,它是一种可以使用Handler的Thread,它的实现比较简单。我们来看看它的源码: 1 package android.os; 2 3 public class HandlerThread extends Thread { 4 int mPriority; 5 int mTid = -1; 6 Looper mLooper; 7 8 public HandlerThread(String name) { 9 super(name); 10 mPriority = Process.THREAD_PRIORITY_DEFAULT; 11 } 12 13 14 public HandlerThread(String name, int priority) { 15 super