android-service

How to run service not on main thread?

感情迁移 提交于 2019-12-09 15:32:44
问题 I'm trying to launch service and then open socket to have connection with server. On button click I create new Thread and then start service. Thread t = new Thread(){ public void run(){ mIntent= new Intent(MainActivity.this, ConnectonService.class); mIntent.putExtra("KEY1", "Value used by the service"); context.startService(mIntent); } }; t.start(); Then on service , I try to open socket and have connection with server @Override public int onStartCommand(Intent intent, int flags, int startId)

Android widget update via service, that is doing http requests

ⅰ亾dé卋堺 提交于 2019-12-09 13:51:27
问题 what is the best strategy for the following scenario: my app will periodically send and receive http requests to a server run PHP script. I tried a service fired by AlarmManager or clicking directly on its widget. Direct operations on the device are working fine (like random numbers, see http://www.vogella.com/tutorials/AndroidWidgets/article.html ) when it comes to the request, these should be done in async tasks. I tried to update the widget (remoteView) from the postexecute section of the

Update service running on background

别来无恙 提交于 2019-12-09 13:44:23
问题 I need to implement such a procedure: Start a background service Update the service with parameters (from UI - user input) After activity ended the service should keep on running and preform requests to HTTP server every minute. in this stage i still need the parameters I updated in the second stage - I send them to the server. The service should store the server last response and compere each with the last. if there is a change, notify the user. Finally, when the activity starts again, the

Camera frames are never captured in background service (Android)

时间秒杀一切 提交于 2019-12-09 06:52:10
问题 I want to run the front camera of a device from a background service, getting the captured frames by the camera in the background service using the callback that's called whenever a new frame is captured by the camera (eg, onPreviewFrame ), and apply some real time processing on the obtained frames. After searching I understand that there are two ways to run the camera in the background: 1- setting a SurfaceView with size 1 X 1. 2- Using SurfaceTexture (This does not require any view which

Close the service when remove the app via swipe in android

只愿长相守 提交于 2019-12-09 05:08:55
问题 I want to close the service when user removes the app from current running app list. Here, what I'm doing, when user starts the app, service gets started and remain in progress. But when user removes the app via swipe, new service is being created. I want to close the service. Below is my code. // Start service using AlarmManager Calendar cal = Calendar.getInstance(); cal.add(Calendar.SECOND, 10); Intent intent = new Intent(this, MyService.class); PendingIntent pintent = PendingIntent

onServiceConnected() not called

余生颓废 提交于 2019-12-08 23:25:57
问题 I have a problem with using a background service. I am using the service from 2 activities. The first activity starts the Service with startService(intent) and the binds to it with bindService(intent, mConnection, Context.BIND_AUTO_CREATE); This works perfectly and I can send a Message in onServiceConnected() . The second activity only binds to the Service (since it's already started), again using bindService(intent, mConnection, Context.BIND_AUTO_CREATE); Now here is my problem: In the

Android: Access Variables passed to service

给你一囗甜甜゛ 提交于 2019-12-08 20:56:24
问题 I have created a service that is called from the main activity and passing it a simple variable to access and toast to the screen from inside the service. I can't seem to find the right code to access the variable from inside the service. Any help would be greatly appreciated. Thanks. Main Activity calling the service from inside a button click listener: @Override public void onClick(View v) { Intent eSendIntent = new Intent(getApplicationContext(), eSendService.class); eSendIntent.putExtra(

startService() throws java.lang.IllegalStateException

对着背影说爱祢 提交于 2019-12-08 19:28:53
问题 From onCreate() of my Activity, I am trying to start a service via following code: Intent intent = new Intent(); intent.setClassName(SERVICE_PKG_NAME, SERVICE_NAME); context.startService(intent); //context = MainActivity.this However, I receive following exception: java.lang.IllegalStateException: Not allowed to start service Intent (service-name) : app is in background Any idea what could be reason for this? Stuck on it for few hours now. 回答1: For cases involving need to invoke service of

How can I get the application context from an Android Service?

谁都会走 提交于 2019-12-08 15:02:40
问题 I have an Android service that is running and listening for microphone input. I want it to launch an activity when a certain criteria is met. In order to create an Intent I need the application context. How can I get it? Intent i = new Intent(ctx, SONR.class); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); ctx.startActivity(i); The above line does not start my activity. Here is my constructor public SONRClient(Context c, AudioRecord ar, int buffsize, final AudioManager am) { theAudioManager = am;

Sync Adapter not calling onCreate

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-08 14:09:19
问题 Do we need to start the Sync Adapter service or framework starts implicitly? I have put a log on Constructor , onCreate , onDestroy of Sync Adapter service and when I start the app, I don't see the logs in the logcat. But when I do on activity onCreate Intent serviceIntent = new Intent(context, SyncService.class); context.startService(serviceIntent); I see the logs. Please suggests. Cheers, Raj 回答1: Sync adapter starts explicitly by calling: ContentResolver.requestSync(ACCOUNT, AUTHORITY,