android-service

When to use and when not to use a Service in Android

自作多情 提交于 2019-12-03 05:11:36
问题 I have been developing for Android for little less then 2 years, and I am still puzzled by this seemingly simple question. When should one implement a service? From my experience there are some rare cases but I am questioning this because on every phone there are quite a lot of them running and I doubt it's just a poor application design. This is essentially core of my question but following are some of my experiences and thoughts about the subject which can explain my question in more detail

Custom Account Type with Android AccountManager

北城余情 提交于 2019-12-03 05:09:54
I have an account type "mypackage.account" and a content authority "mypackage". I have a Service that provides an implementation of AbstractAccountAuthenticator , the addAccount method is implemented like this: /** * The user has requested to add a new account to the system. We return an intent that will launch our login * screen if the user has not logged in yet, otherwise our activity will just pass the user's credentials on to * the account manager. */ @Override public Bundle addAccount(AccountAuthenticatorResponse response, String account_type, String auth_token_type, String[] required

Is it good to replace broadcast receiver with Greenrobot Eventbus for triggering event based functions and data transfer from service to activity?

谁都会走 提交于 2019-12-03 05:05:44
问题 I have implemented a service, where I handle the state changes(connect, disconnect, onServiceDiscoverd, onCharacteristicChange etc) and receiving data from another device through gatt Server. My question is, Can the events be handled efficiently using Greenrobot Eventbus replacing broadcast receiver between service and Activity ? 回答1: Unlike LocalBroadcastManager, EventBus is more simple to use. You only go via 3 steps: 1- Create an event class. A simple Java class that represent the response

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

how to prevent service to run again if already running android

送分小仙女□ 提交于 2019-12-03 04:14:41
On click of a button I want to start service using method startService(new Intent(currentActivity.this,MyService.class)) but if service is running I don't want to call this method to avoid run service that is already running.How this is possible.I am using both Intent service and Service in same project and want to apply same condition for both. A service will only run once, so you can call startService(Intent) multiple times. You will receive an onStartCommand() in the service. So keep that in mind. Source: Note that multiple calls to Context.startService() do not nest (though they do result

how to start service from fragments

拥有回忆 提交于 2019-12-03 04:14:29
问题 I want to start service from fragment from a list view item. I am trying to call service with: startService(new Intent(getActivity(),myPlayService.class)); But it wont work at all. How do i call my service from fragments? Is there any another way to start service? 回答1: Replace startService(new Intent(getActivity(),myPlayService.class)); with getActivity().startService(new Intent(getActivity(),myPlayService.class)); 来源: https://stackoverflow.com/questions/13007355/how-to-start-service-from

List of Android task killers

て烟熏妆下的殇ゞ 提交于 2019-12-03 03:58:46
I am trying to do a list of Android task killers that are installed by default on the operating system. The problem is that Android is modified by the phone's manufacturer and it is hard to keep up with what everyone is doing. So far I have found this: Smart manager - On Samsung phones. Could not call alarm manager but you can avoid this if your package name contains "alarm" or "alert" Doze - On Android 6. should not interrupt the app but it may delay alarm manager or network processes(especially if your app is not active and your phone is not charging). Xiaomi , AutoStart . If AutoStart is

onTaskRemoved of a Android Service is never being called ! Why?

纵然是瞬间 提交于 2019-12-03 03:54:29
I am stuck with a issue from last 2 days, I want to hit a api and show user a Toast when user swipe off the app from Background Task, I found that from service it is possible as onTaskRemoved is called when app is removed from background. Code : MyService.java public class MyService extends Service { private static final String TAG = MyService.class.getSimpleName(); Handler mHandler; @Override public void onCreate() { super.onCreate(); mHandler = new Handler(); } @Nullable @Override public IBinder onBind(Intent intent) { return null; } @Override public int onStartCommand(Intent intent, int

Running Android TTS in a Service

感情迁移 提交于 2019-12-03 03:37:07
I'm trying to get Android's TTS to run inside a service, but I have no idea why it isn't working, it compiles, doesn't crash, but it just doesn't work. The Toast notification do work though. package alarm.test; import android.app.Service; import com.google.tts.TextToSpeechBeta; import android.content.Intent; import android.os.IBinder; import android.widget.Toast; public class MyAlarmService extends Service { private TextToSpeechBeta myTts; private TextToSpeechBeta.OnInitListener ttsInitListener = new TextToSpeechBeta.OnInitListener() { public void onInit( int arg0, int arg1 ) { myTts.speak("",

Draw an Android canvas on top of all applications?

a 夏天 提交于 2019-12-03 03:30:33
I suspect this isn't possible, given the nature of Android, but is there a way to create a view of sorts (perhaps using a Canvas object?) that is shown on top of all applications? My intent for this project is not malicious. I have created some simple Color Filter software for Windows that simply adds a window on top of all windows, which is filled with a user-chosen color, and has a low opacity. This adds a light tint to the screen which helps users with Scoptopic Sensitivity Syndrome use a computer for long periods of time. I would like to make an Android version of this software. For