android-service

Online Transaction: asynctask vs service

非 Y 不嫁゛ 提交于 2019-12-11 12:48:30
问题 Given the use case where the user has to perform an online transaction, eg online payment, using the app. This should be done without blocking the UI, so i was going to use AsyncTask. The problem is with the following scenario: - the user rotates the phone or gets an incoming call in the middle of the transacion, thus causing the activity to be destryed. If I understood correctly the asynctask now has a reference to a stale object. So after the transaction is done, there is no way to inform

start a service in onCreate of Application

有些话、适合烂在心里 提交于 2019-12-11 12:45:23
问题 I am trying to start a service when my app begins, and I need it the service to restart, incase a user decides to force close the service, even though the app is running(its ok, for him to force close the app, but i need to prevent closing of service while the app is running). So i went about extending the Application class, and this is what I am doing to start the service... ServiceConnection conn = new ServiceConnection() { public void onServiceConnected(ComponentName className, IBinder

Android AOSP compilation error - can't find import in aidl file

╄→尐↘猪︶ㄣ 提交于 2019-12-11 12:33:26
问题 I am trying to modify AOSP by adding a new system service. I have the aidl for the service as follows : package android.app; import java.util.ArrayList; import android.app.TypeA; import android.app.TypeB; interface myService { ArrayList<TypeA> getA(); ArrayList<TypeB> getB(); } TypeA and TypeB are implementing Parcelable interface, still when I try to build Android, it fails to import these 3: couldn't find import for class java.util.ArrayList couldn't find import for class android.app.TypeA

Passing extras from Activity to Intent throws NullPointerException

我只是一个虾纸丫 提交于 2019-12-11 12:04:08
问题 This is a problem that forked off a different issue. I'm passing two strings from my main activity to a child service, which is fine, but when the main activity dies, the service throws a NullPointerException trying to grab the two strings. From MainActivity: Intent i = new Intent(this, PebbleService.class); i.putExtra("quote", quote[0]); i.putExtra("author", quote[1]); startService(i); From PebbleService: public int onStartCommand(Intent intent, int flags, int startId) { super.onStartCommand

Binding few activities to one service - class which connected treated like service - can't destroy activity

吃可爱长大的小学妹 提交于 2019-12-11 11:58:07
问题 I will start from my approach I want to have one service which is running even if none of application screen is visible for user. This service will scan for beacons. Every screen of application needs to get access to method of service so I used binding to service here. I designed serviceconnector class which will be connecting Activities with service, this class look like this. import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android

ANDROID - service called by AlarmManager wont stop after destroy

巧了我就是萌 提交于 2019-12-11 11:25:10
问题 i have a service getting started by Alarm Manager set to be repeated: AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE); serviceSaveSample = new Intent(RunActivity.this,SaveSampleService.class); alarmSaveSample = PendingIntent.getService(getApplicationContext(), 9988766, serviceSaveSample, PendingIntent.FLAG_CANCEL_CURRENT); alarm.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (secondsToSample*1000) , secondsToSample*1000, alarmSaveSample); my

Android - How to start service and activity on same time?

给你一囗甜甜゛ 提交于 2019-12-11 10:17:28
问题 I want to start service and activity on same time. I am using the following code, It is correct? startService(new Intent(this, Service.class)); Intent intent = new Intent(this, Activity.class); startActivity(intent); But here after service is complted then only Activity starting. Why? Please help anyone. 回答1: You can try to launch few threads and use semaphore with barier flag. 回答2: There is no way to start an Activity and a Service that run in the same process (which is the default behaviour

Send data from service to bound activity periodically

冷暖自知 提交于 2019-12-11 09:48:36
问题 I have an Activity that starts and binds to a service. It sends an intent with a List of data and the service is responsible for periodically updating that data. This is done in the handleIntent (Intent) method. What I want to do is send the updated data back to the activity. Both the activity and the service are in the same application. How can I "listen" for requests from my service? Do I have to use a Messenger and/or Broadcast Receiver? what's the cleanest, easiest, most efficient way of

How to stop a system service?

◇◆丶佛笑我妖孽 提交于 2019-12-11 09:31:57
问题 I want to know how to stop a system service using my app in android, I'm not talking here about stopping a Service Class that exists inside my app, I'm taking about stopping a System Service like ( Bluetooth , Mailing , Alarm , WiFi , .....etc) I tried to make it like the following but nothing stopped: stopService(new Intent(Service.BLUETOOTH_SERVICE)); 回答1: I want to know how to stop a system service using my app in android, In the UI of your app, you ask the user to completely power down

Service onStartCommand throwing NullPointerException

不羁的心 提交于 2019-12-11 08:47:27
问题 I have an app that runs two separate services. One of them runs smoothly, and the other works without issue a majority of the time, but is throwing a NullPointerException within onStartCommand() intermittently on a significant number of newer devices (Samsung, HTC, LG) on varying Android versions between 4.1 and 4.4.2. I am unable to reproduce the error on any of my own devices, including two of the exact models which have experienced this issue. The stacktrace is as follows, indicating the