android-service

How to simulate a service killed by the Android system

丶灬走出姿态 提交于 2019-11-30 20:17:07
While developing I wanted to test the situation where the system kills a service. This is because I'm loosing connection when communicating between the Android Wear and the handheld. And I think that it is related with the system killing some services. Does anyone have a suggestion on how to approach this? cdlc if you're developing in Android Studio while you are running your application in android wear side try to hit the kill button displayed in the console. When you hit this button all the threads + services + activities from this app will be destroyed. If your service is of type "STICKY"

Getting window display from service android

房东的猫 提交于 2019-11-30 19:50:31
I am trying to display a window from service but don't getting it how to do this Here is my code-- In onStart method of Service LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.main1, null); WindowManager manager = (WindowManager) getSystemService(WINDOW_SERVICE); WindowManager.LayoutParams params = new WindowManager.LayoutParams(); params.type = 2002; params.format = 1; params.flags = 40; params.height = WindowManager.LayoutParams.FILL_PARENT; params.width = WindowManager.LayoutParams.FILL_PARENT; manager.addView(view,

Send data from Service to Fragment, Android

ぐ巨炮叔叔 提交于 2019-11-30 19:34:21
问题 Good evening! I have small problem with Service. At first, I have fragment with several TextViews. Into these TextView I want put text from my Service. And this code of my simple Service public class ChallengeService extends Service { final String LOG_TAG = "myLogs"; private String url = ""; public static ArrayList<Exercises> exercises = new ArrayList<>(); public void onCreate() { super.onCreate(); Log.d(LOG_TAG, "onCreate"); } public int onStartCommand(Intent intent, int flags, int startId)

Permission issue while starting a service from android

三世轮回 提交于 2019-11-30 17:50:16
I have written a service as part of an application. I try to call this service from a second application using the following code: Intent intent = new Intent () ; intent.setClassName("com.test" ,"com.test.DownloadService") ; // Create a new Messenger for the communication back Messenger messenger = new Messenger(handler); intent.putExtra("MESSENGER", messenger); intent.setData(Uri.parse("http://www.vogella.com/index.html")); intent.putExtra("urlpath", "http://www.vogella.com/index.html"); this.startService(intent); It gives the following exception 07-10 09:27:28.819: ERROR/AndroidRuntime(4226)

Start a service from Thread.UncaughtExceptionHandler?

匆匆过客 提交于 2019-11-30 17:27:55
问题 I'm trying to setup a global exception handling service as mentioned in this answer. This approach sounds logical because after a crash, the code in my custom Thread.UncaughtExceptionHandler may not execute successfully, either because the application may not be in a stable state or because there may not be enough time before the process is killed by the OS. Unfortunately, this approach doesn't seem to work because the service launches in the same process so it, too, is killed. How can I

Not getting the updated value of the shared preference in the service

a 夏天 提交于 2019-11-30 17:19:58
问题 I am storing some value to a shared preference from an activity which launched from a widget. If I retrieve that value from the service started from the same widget, it is not the updated one. I am getting the previous value had in the shared preference. Even i check that value in the shared preference xml, i sees the updated one there. Why this is happening. I know that widget and activity are two process, is that the reason?​ SharedPreferences preferences = getSharedPreferences("preferences

Android keep BroadcastReceiver in background

夙愿已清 提交于 2019-11-30 17:18:44
问题 I created a BroadcastReceiver and it runs only when my app shown in recent apps menu. If I remove my app from the recent apps the BroadcastReceiver will stop working. How can I keep the BroadcastReceiver in background? I register the BroadcastReceiver from my main activity (in OnCreate()). IntentFilter intentFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); registerReceiver(receiver, intentFilter); BroadcastReceiver receiver = new BroadcastReceiver() { @Override public void onReceive

Problems in Calling AsyncTask from IntentService

柔情痞子 提交于 2019-11-30 17:17:20
问题 I have created IntentService class and performing asyncTask but getting exception when onPreExecute() is called at this code line pDialog.show(); AsyncHandlerService Class --- public class AsyncHandlerService extends IntentService{ ProgressDialog pDialog; HttpPost post; HttpResponse response; Context ctx; public AsyncHandlerService() { super("AsyncHandlerService"); ctx = this; } @Override protected void onHandleIntent(Intent intent) { new LoadDeviceInfo().execute(); } class LoadDeviceInfo

Start Android TTS from Broadcast Receiver or Service

两盒软妹~` 提交于 2019-11-30 16:39:25
I'm trying to get TTS to run in the background. But, I never get any sound. I have a broadcast receiver which starts a service. I put my TTS code in both of those, but it never speaks. I know the method is being called (I put a breakpoint on it), but it still doesn't work. Here's my log, but it doesn't seem to contain anything about the TTS service. 10-04 22:45:30.663: WARN/InputManagerService(209): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@4423df40 10-04 22:45:37.363: INFO/PollingManager(449): calculateShortestInterval(): shortest

java start one background thread after another complete

♀尐吖头ヾ 提交于 2019-11-30 16:34:12
I saw this question: how to run one thread after complete another thread , but the answer to it is not appropriate for me. I have such kind of java code for Android: public void startTask(Runnable r) { running = true; Log.i(tag, "-----------start.Runnable-----------"); Thread first = new Thread(r); first.start(); Thread second = new Thread(new Runnable() { @Override public void run() { // TODO Auto-generated method stub running = false; } }); } first Thread takes as param Runnable object with some hard operation which I am processing in background service. So, when I call method: startTask() I