android-service

Android simple service not starting

陌路散爱 提交于 2019-12-25 07:34:41
问题 My problem is in the question title, i'm trying to start/bind a simple service with just log in it and it's not working at all. I want to do it with Service Connexion method : public class testServiceBound extends Service { /** * PRIVATE ATTRIBUTES */ // log private static final String TAG = testServiceBound.class.getSimpleName(); private final Binder _binder = new testBinder(); @Override public void onCreate() { Log.i(TAG, "onCreate--"); super.onCreate(); } @Override public int

Android service scheduled on AlarmManager not starting

久未见 提交于 2019-12-25 07:31:21
问题 I have a service (properly declared in the Manifest file) that upon onDestroy() schedules itself to start again one minute later via AlarmManager . However the service is not starting even though onDestroy() runs correctly. What could be wrong? The scheduling code: @Override public void onDestroy() { BroadcastReceiver br = new BroadcastReceiver() { @Override public void onReceive(Context c, Intent i) { c.startService(new Intent(c, MyService.class)); } }; registerReceiver(br, new IntentFilter(

Android sensor registerListener in a separate thread

余生颓废 提交于 2019-12-25 07:21:18
问题 I have wrote a service to log accelerometer values in background. The idea is to register for sensor listener and write the values to storage. I have enabled the StrictMode.enableDefaults() in the MainActivity of the app (not in the service) to check if the service runs on its own thread. But it does not! I don't know what is the problem...I have this AsyncTask class that I hoped to take care of the problem but it apparently did not (this is inside the service and its execute method is called

External service can not be resolved by intent filter

浪尽此生 提交于 2019-12-25 07:19:00
问题 I am missing something essential or... I have two applications, one of them containing exported service with intent filter declared in AndroidManifest: <service android:name=".MyService" android:exported="true" android:permission="my.permission" > <intent-filter> <action android:name="my.service" /> </intent-filter> </service> I can successfully bind to that service from another application by using "my.service" action. But I want to start service (send command to it). If I write: Intent

android - how can I stop the thread inside the service?

那年仲夏 提交于 2019-12-25 04:22:25
问题 I have a checked button in my MainActivity. If that button is checked it should start the service but if a user unchecked the button I want to stop the service. So in uncheck condition I have written this stopService(intentname); but the problem is the service is not stopping. Here is my code snippet: Service Class public class SimpleService extends Service { String selectedAudioPath = ""; private MyThread myythread; public Intent intent; public boolean isRunning = false; long interval=30000;

Starting an Android notification at startup

人走茶凉 提交于 2019-12-25 03:04:20
问题 This question is based off of this previous question of mine: Android - Set notification to never go away I now realize that I need something to be triggered at startup to trigger the notification. From my previous question, it looks like I can take two routes. Either start a service, or use a BroadcastReceiver. I think that starting a service is a little overkill (but what do I know). I am stuck while going with the BroadcastReceiver route. It works in general, but when I take my code for a

Getting battery status even when the application is closed

好久不见. 提交于 2019-12-25 03:03:42
问题 Hey I am trying to make an application that tells me when the battery is full when the phone is connected to power. I made a service and used a broadcast receiver in that to check the battery status. Whenever i connect or disconnect the phone from the power, my app crashes. The service still runs and i get the notification when battery is full. I dont know why is the app crashing again and again. Here is my code public class Srvc extends Service{ @Override public int onStartCommand(Intent

Service Broadcast Receiver Logs more than expected

旧街凉风 提交于 2019-12-25 02:29:00
问题 My problem is that I think my service runs multiple times. The service is controlled by a switch calling a method that starts and stops the service. I have a broadcast listener inside my service and the receiver logs whenever it receives a broadcast. at first switch on, it logs two times. After switch off and on, it logs four times. public class Service1 extends Service implements DetectionListener { private static final String TAG = "ListenerService"; private final broadcastReceiver1

sending data to server from text file using a service

你离开我真会死。 提交于 2019-12-25 01:53:05
问题 I am sending data from text file to server using service code given below. It sends data line by line to server. I want the service to run in background continuously.For this I have written asyncTask. But it sends all data once and then stops. public class BackgroundService extends Service { private static final String TAG = "BackgroundService"; String line=null; Context mContext = null; File file;RandomAccessFile in = null; StringEntity se ; HttpEntity entity=null; final static int SERVICE

Android keep BroadcastReceiver while the app is closed

荒凉一梦 提交于 2019-12-25 00:38:02
问题 I use BroadcastReceiver of ACTION_BATTERY_CHANGED to get an event every time the battery is 50%. I can't declare ACTION_BATTERY_CHANGED in manifest, so I declared the BroadcastReceiver in a Service (START_STICKY). But, when I remove the app from recent apps screen the BroadcastReceiver stops getting battery change events. How can I keep it in background? *In many apps that show battery percent in status bar, the percent is updated while the app is closed. How? 回答1: You really cannot do what