android-service

executing asynchronous task from service in android

本秂侑毒 提交于 2019-12-11 08:23:03
问题 I was developping an application and I ran into a problem. I was trying to run an asynchronous task from a service and it didn't work. It says that the code is unreachable. Now I knwo that both run in Background, but I really want one service to control several asyncronous tasks. how can I do that? Do I have to use threads? I've read this post and I really want to use the asyncronous task: Difference between Service, Async Task & Thread? Also, is it possible to execute an asynchronous task

registerReceiver from IntentService doesn't hit BroadcastReceiver

白昼怎懂夜的黑 提交于 2019-12-11 08:00:35
问题 I've created an IntentService for downloading a file using Android's DownloadManager. Following is my Class: public class DownloadService extends IntentService { public DownloadService() { super("name"); } BroadcastReceiver onComplete = new BroadcastReceiver() { public void onReceive(Context ctxt, Intent intent) { function(); } }; @Override protected void onHandleIntent(Intent intent) { registerReceiver(onComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); Utility.download

How to send a notification when the app is closed?

感情迁移 提交于 2019-12-11 07:59:58
问题 I want a notification to happen whenever a child is added from my firebase database. I have the below code working within onChildAdded() while the app is running or in the background, but obviously not when it's closed. I read something about starting a service but was a bit overwhelmed. NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mRecyclerView.getContext()) .setSmallIcon(R.drawable.icon) .setContentTitle("Title") .setContentText("Content Text"); Intent

onServiceConnected not getting called , getting a null pointer exception

风流意气都作罢 提交于 2019-12-11 07:54:30
问题 I had developed a bound service as a separate project & I am trying to access the service from a client but I somehow I am getting AndroidRuntime: FATAL EXCEPTION: main 08-08 12:00:40.898 3206 3206 E AndroidRuntime: java.lang.NullPointerException 08-08 12:00:40.898 3206 3206 E AndroidRuntime: at com.test.binder.BinderServiceActivity.onClick(BinderServiceActivity.java:61) 08-08 12:00:40.898 3206 3206 E AndroidRuntime: at android.view.View.performClick(View.java:3526) 08-08 12:00:40.898 3206

Insert to room in service not updating LiveData in activity

情到浓时终转凉″ 提交于 2019-12-11 07:47:25
问题 I'm using room to communicate data fetched by a foreground Location service with the an activity. The service connects to the viewmodel and does insert data, the activity however does not receive updated LiveData from the viewmodel, it is however able to fetch a LiveData> object at the begining, with accurate size when restarting the app. What am I missing here? I need to insert new data into the db, so if I do need to use MutableLiveData in the service and postValue, then I would have to

Use alarmManager and service to get data from server repeatedly

喜你入骨 提交于 2019-12-11 07:37:36
问题 My question is I want to verify every two hour that there is new data in the database, for that I create this user interface : <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <EditText android:id="@+id/speedAlert" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ems="10" android:gravity="center" android:hint="km/h" android:inputType=

Xiaomi Redmi Note 3 custom service not working?

我们两清 提交于 2019-12-11 07:33:29
问题 Xiaomi Redmi Note 3 ,Any Custom service creating using code is disable when you clear application from background, issue not happen in samsung and other phone but happen in similar phones. 回答1: You need to add your app to the list of "protected apps". On different phones this is in different places, try looking in "settings->Security". You need to explicitly enable your app to run in the background. 来源: https://stackoverflow.com/questions/45419571/xiaomi-redmi-note-3-custom-service-not

Sending continuos data from service to activity at really very high speed

烈酒焚心 提交于 2019-12-11 07:30:12
问题 I am developing a testing application on an Architecture which is based on Producer-Consumer structure. I have an producer-consumer* problem, especially if an producer callback mechanism is utilized in android service i.e. consumer. Consumers are not supposed to hold the call for more than the minimum necessary time to have the info handed over. Since the producer’s callbacks are supposed to run in a different thread than the consumer’s one. In my specific case within the callback of Producer

Onresume method for Android services

左心房为你撑大大i 提交于 2019-12-11 07:20:00
问题 I am trying to make a service which waits NFC tags and does something. I can do it with following code block in an activity but have no idea, even after researches, how to implement it in a service. @Override protected void onResume() { super.onResume(); // Sticky notes received from Android if enableNdefExchangeMode(); if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) { do_something(); } } I want to do this in a service. i can not use super.onResume(). What should I use

How does apps like Whatsapp or telegram listen to the incoming call/message events on Android?

≡放荡痞女 提交于 2019-12-11 07:05:40
问题 I built a VoIP calling app which maintains a persistent connection with the server to listen to any incoming calls. I implemented a background service to do this. But since Oreo, this running code is now broken because of the introduction of Background Execution Limits After looking into forums, I found that some people are suggesting Convert Service to JobService and let android schedule it Doing so, my app won't be able to receive calls when it is stopped Run your operations in foreground