android-service

Download multiple files with a progress bar in ListView Android

萝らか妹 提交于 2019-11-26 09:15:54
问题 I want to create a ListView that allows the user to download many files and show a progress bar status in each ListView item. It looks like this: The download ListView has some rules: Each download task displays in one ListView item with a progress bar, percentage and current status (downloading, waiting, finished). Allow a maximum of 5 download tasks, other tasks have to wait Users can cancel the download task, and remove this task from the ListView The ListView is in the download activity.

The process of the service is killed after the application is removed from the application tray

不问归期 提交于 2019-11-26 08:59:35
问题 I am starting a service (or re-starting the running service) when an activity is launched, using : Intent intent = new Intent(this, MyService.class); startService(intent); Later on based on certain actions, the same activity binds to the service using bindService(new Intent(this, MyService.class), mConnection, Context.BIND_AUTO_CREATE); And when the activity is destroyed, I call unbindService(mConnection); Earlier, the service used to restart when I killed the same activity/application from

How to find the currently running applications programmatically in Android?

こ雲淡風輕ζ 提交于 2019-11-26 08:51:20
问题 I am very new to Android. I am working on application that must get the information about the applications currently running on foreground. It means if user launches any applications, my application should capture the launched application information, by the time my application shouldn\'t interrupt launched application. Example: If user launches browser application my application should print browser application information on log. How can I do this? 回答1: ActivityManager activity_manager =

Android L (API 21) - java.lang.IllegalArgumentException: Service Intent must be explicit

纵然是瞬间 提交于 2019-11-26 07:47:35
问题 Android new version - \"Lollipop\" (API 21) brings quite a few changes with it, but it comes with some price if you wish to target your app to that API. When we started adapting our apps to the new API, one of the first problems we\'ve encountered is the IllegalArgumentException: Service Intent must be explicit If you have encountered the problem, and you are actually intending to use your intent in explicit way (meaning that when starting the service you are expecting to hit exactly 1

START_STICKY does not work on Android KitKat

我怕爱的太早我们不能终老 提交于 2019-11-26 06:45:36
One of my apps has a backgrouod service that uses the START_STICKY return code from onStartCommand to automatically restart when the system kills it. It seems that this is no longer working on Android KitKat. Is there any solution for this ? Should I be doing something different on Kitkat to keep the service running ? Note: There is a similar discussion on the Android-Devlopers group about swiping the app from the recent apps list behaves. Could this two issues be related ? https://groups.google.com/forum/#!topic/android-developers/H-DSQ4-tiac Edit: Saw that there are open bugs on Android

Android onCreate or onStartCommand for starting service

◇◆丶佛笑我妖孽 提交于 2019-11-26 06:25:13
问题 Usually when I create an Android service I implement the onCreate method, but in my last project this does not work. I tried implementing onStartCommand , and this seems to work. The question is: when I have to implement a service which method is required? Which methods I have to implement? onCreate , onStartCommand , or both? And what is the role of each? 回答1: onCreate() is called when the Service object is instantiated (ie: when the service is created ). You should do things in this method

How to always run a service in the background?

邮差的信 提交于 2019-11-26 05:59:21
问题 I am in the process of creating an app that is similar to the built-in SMS app. What I need: a service that is always running in the background every 5 min. the service checks the current location of the device and calls a web service if certain criteria are met, the service should generate a notification (just like the SMS app) when the notification is clicked, the user is taken to the app (just like the SMS app) when the app is installed the service should be started when the device is

How can we prevent a Service from being killed by OS?

与世无争的帅哥 提交于 2019-11-26 05:55:35
问题 I am using Service in my application and it needs to run until my application is uninstalled, but the problem is it gets killed by OS. How can we prevent it from being killed by OS? Or if it gets killed can we restart that service again through programmatically? 回答1: You may run the service in the foreground using startForeground(). A foreground service is a service that's considered to be something the user is actively aware of and thus not a candidate for the system to kill when low on

How to get the current location latitude and longitude in android

心已入冬 提交于 2019-11-26 05:49:43
问题 In my application, I get the current location\'s latitude and longitude when application is open, but not when the application is closed. I am using Service class to get the current location latitude and longitude in my application. Please tell me how to get the current location latitude and longitude even when application is closed 回答1: Before couple of months, I created GPSTracker library to help me to get GPS locations. In case you need to view GPSTracker > getLocation Demo AndroidManifest

How to run an android app in background?

本小妞迷上赌 提交于 2019-11-26 05:29:41
问题 This code will run an app automatically after booting the system, but the app will close after pressing the back button. If the app is run normally by clicking it\'s icon. It will continuously run even after pressing the back button or running other apps. public class AutoBoot extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Intent i = new Intent(context, MyActivity.class); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); } } My