android-service

Getting 'You need to use a Theme.AppCompat theme (or descendant) with this activity.' while trying to show an AlertDialog from BroadcastReceiver

北慕城南 提交于 2019-12-08 10:28:08
问题 I'm sending a Broadcast from a service and then receiving it back from inner BroadcastReceiver class. I have to show an AlertDialog based on some logic but while trying to do it, I'm getting this runtime error: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. Here's MyBroadcastReceiver class: public class MyBroadcastReceiver extends BroadcastReceiver { public MyBroadcastReceiver(){ super(); } @Override public void onReceive(final

doInBackground from AsyncTask never called when Service work on background

做~自己de王妃 提交于 2019-12-08 08:45:13
问题 private class Test extends AsyncTask<Void, Void, Void> { @Override protected void onPreExecute() { // TODO Auto-generated method stub super.onPreExecute(); Log.d("test", "called1"); } @Override protected Void doInBackground(Void... params) { Log.d("test", "called2"); return null; } @Override protected void onPostExecute(Void result) { // TODO Auto-generated method stub super.onPostExecute(result); Log.d("test", "called3"); } } and output: test:called1 Why other methods never don't called when

How to schedule an android service to execute at a fixed rate

纵然是瞬间 提交于 2019-12-08 07:29:22
问题 I am working on an application that should download a file from the network every X seconds to check for any change, I use a service to do that, but its execution is not fixed with the delay time rate, here is my code for the service: @Override public int onStartCommand(Intent intent, int flags, int startId) { Toast.makeText(this, "service starting", Toast.LENGTH_SHORT).show(); checkUpdate(); return START_STICKY; } private Void checkUpdate() { timer.scheduleAtFixedRate(new TimerTask() {

Android Wake lock remains after Doze mode?

倖福魔咒の 提交于 2019-12-08 07:19:00
问题 Iam trying to simulate the Doze mode while my app is running in the background. What happens is that the thread will continue to run, even though the device has entered Doze mode. The docs specifies that wake locks are ignored, so why cpu is still on? Tested On: Emulator with Api 27 JobScheduler jobScheduler = (JobScheduler)getApplicationContext() .getSystemService(JOB_SCHEDULER_SERVICE); ComponentName componentName = new ComponentName(this, MyJob.class); JobInfo jobInfo = new JobInfo.Builder

How to receive missed messages on resuming connection lost in pubnub?

蹲街弑〆低调 提交于 2019-12-08 06:58:34
问题 I tried https://github.com/pubnub/java/tree/master/android#connection-durability-reconnecting--resuming-when-a-connection-is-lost-or-changed but still I'm not able to figure out how to use setResumeOnReconnect() . I'm running android-service and added following code snippet inside onCreate() of the service. pubnubBroadcastReceiver =new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { ConnectivityManager connectivityManager = (ConnectivityManager)context

Resume background activity on notification

◇◆丶佛笑我妖孽 提交于 2019-12-08 05:38:42
问题 I've read some answers here, I think I have what I need in order to achieve my result, but I need some help. My app launches an notification on specific conditions, and I need my app to behave as follow: if there is an instance of my main activity running in background I need to make it to the foreground (I found this on the site: intent.setFlags(FLAG_ACTIVITY_REORDER_TO_FRONT); , so I think this point is solved; if there isn't any activity of the app running in background I need to start the

Communication between Service and Activity each hosted in different process using PendingIntent

南笙酒味 提交于 2019-12-08 05:25:02
问题 I am starting a foreground service from a fragment which gets destroyed after call to startService() , which is a reason I can't use ResultReceiver or Messanger . So the option remains PendingIntent . How can I communicate between foreground service(hosted in different process) from any activity/fragment using PendingIntent? 回答1: You have two separate issues: How do you get data from the service process to the UI process? How do you get the data from whatever you did for #1 to whatever

How to properly upgrade AIDL interfaces in Android?

不打扰是莪最后的温柔 提交于 2019-12-08 04:37:47
问题 I have two apps: One is called my-app.apk , the other my-service.apk . The service app just defines a single Android Service, which can be bound by the primary app to execute some methods. This is done using Androids AIDL interface, and it works great - so far. Now I want to change the interface of the service, and I am wondering what I have to watch out for. I changed the file IRemote.aidl of my-service.apk to the following: package com.example.myservice; interface IRemote { void printHello(

IntentService connected to Server listening

。_饼干妹妹 提交于 2019-12-08 04:13:11
问题 I coded an IntentService where I send a command line. Is related to an activity where I'm trying to program a Console. The activity's purpose is to do a 'command prompt' where I can send and receive to/from the server. The Service's action is: COnnect to the server Send command line Get response Retrieve response to user The main problem is that every time I send a command line, the Service has to reconnect to the server. (Cause every time I'm starting the whole Service) How can I avoid this

doInBackground from AsyncTask never called when Service work on background

南笙酒味 提交于 2019-12-08 04:01:26
private class Test extends AsyncTask<Void, Void, Void> { @Override protected void onPreExecute() { // TODO Auto-generated method stub super.onPreExecute(); Log.d("test", "called1"); } @Override protected Void doInBackground(Void... params) { Log.d("test", "called2"); return null; } @Override protected void onPostExecute(Void result) { // TODO Auto-generated method stub super.onPostExecute(result); Log.d("test", "called3"); } } and output: test:called1 Why other methods never don't called when Service work on background? If service stop, then all method calls and output: test:called1 test