intentservice

How to create toast from IntentService? It gets stuck on the screen

☆樱花仙子☆ 提交于 2019-11-27 01:47:59
问题 I'm trying to have my IntentService show a Toast message, but when sending it from the onHandleIntent message, the toast shows but gets stuck and the screen and never leaved. I'm guessing its because the onHandleIntent method does not happen on the main service thread, but how can I move it? Has anyone has this issue and solved it? 回答1: in onCreate() initialize a Handler and then post to it from your thread. private class DisplayToast implements Runnable{ String mText; public DisplayToast

How to use Notification.deleteIntent

喜夏-厌秋 提交于 2019-11-27 01:37:02
问题 I'm trying to detect when my notification gets cleared. My question directly refers to this answer which outlines what I'm suppose to do. This is how I'm implementing the actions: // usual Notification initialization here notification.deleteIntent = PendingIntent.getService(context, 0, new Intent(context, CleanUpIntent.class), 0); notificationManager.notify(123, notification) This is the CleanUpIntent class: class CleanUpIntent extends IntentService { public CleanUpIntent() { super(

Android Work Manager vs Services?

淺唱寂寞╮ 提交于 2019-11-27 01:20:49
问题 In my Android app i have multiple intent services which run one after another and the very first intent service is trigerred by a broadcast. I came across Work Manager a few days ago and really liked the simplicity of the Worker and the WorkManager classes. What are the pros and cons of Work Manager over regular intent services? Should i switch to work manager now considering the fact that i may have to write more intent services in the future? Also which option would help me test the code

Android: Using WebView outside an Activity context

陌路散爱 提交于 2019-11-26 21:57:16
I am trying to achieve Web Scraping through a background IntentService that periodically scrape a website without a view displaying on the users phone. Since I have to do call some javascript on the loaded page I cannot use any HttpGet's etc. I therefore have to use a WebView instance which can only run on an UI thread. Any attempts to start an Activity that use a WebView results in a View coming into the phones foreground (as per Android's design of Activities) Any attempts to use a WebView outside of an Activity context resulted in error pointing to the fact that you cannot use WebView on a

Android how to check if the intent service is still running or has stopped running

て烟熏妆下的殇ゞ 提交于 2019-11-26 18:55:23
问题 I need to know if all intentservices in the queue are "consumed" or the other way is to find out if it is still doing something so that I don't continue until all services have stopped running. Any ideas? 回答1: Try this may be useful for u private boolean isMyServiceRunning() { ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE); for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { if ("com.example.MyService".equals(service.service

Need Help in Downloading in Background Images in Android?

僤鯓⒐⒋嵵緔 提交于 2019-11-26 17:59:49
问题 I have an image view , i had written swiping , at that time of swiping,the images are downloading from Internet, so i thought i have to download the images in the background before swiping , for that which i need to use asynctask or Service or IntentService, all these will help in downloading and storing in data/data/mypackages , but still swiping gets slow in my case any idea, also convey me which one is best one, is it i'm calling in a right way 1. asynctask 2. services 3. Intent Service as

How to use CPU to perform any operation in Deep Sleep mode

折月煮酒 提交于 2019-11-26 17:52:31
问题 I'm new in android . I struggle with my application approximately 3 weeks. I need sent and receive packets in normal mode and sleep mode . My app must exchange data a 5 seconds. I tried using alarmmanager but on android 5 it's not works. On android 5 an interval changes it on 60 seconds. Such a solution makes the battery wears out quickly. When I use normal asynctask, not IntentService , then it works only when screen is ON and app is visible. When app is hidden or I click power OFF then

Android: keep Service running when app is killed

早过忘川 提交于 2019-11-26 15:14:31
I want to keep a IntentService running in background even when the app is killed. And by "killed" I mean press home-button for a long time -> see all running apps -> swipe my app aside -> app killed OR press back-button for a long time -> app killed My code goes as follows. In my MainActivity: Intent intent = new Intent(this, MyService.class); this.startService(intent); In my MyService: public class MyService extends IntentService { @Override protected void onHandleIntent(Intent intent) { System.out.println("MyService started"); run(); } private void run() { while (true){ System.out.println(

Proper way to stop IntentService

前提是你 提交于 2019-11-26 14:20:30
问题 I'm using an IntentService to upload images to a server. My problem is that I don't know how/when to stop the service. When I call stopself() in onHandleIntent(Intent ..) all Intents which are waiting in the IntentService queue are removed. But I don't want to stop the service from an activity because I want to complete upload proccess even if my application is not running. 回答1: My problem is that I don't know how/when to stop the service. IntentService automatically stops itself when

How to force an IntentService to stop immediately with a cancel button from an Activity?

我的未来我决定 提交于 2019-11-26 12:13:47
问题 I have an IntentService that is started from an Activity and I would like to be able to stop the service immediately from the activity with a \"cancel\" button in the activity. As soon as that \"cancel\" button is pressed, I want the service to stop executing lines of code. I\'ve found a number of questions similar to this (i.e. here, here, here, here), but no good answers. Activity.stopService() and Service.stopSelf() execute the Service.onDestroy() method immediately but then let the code