android-service

If android restarts a Service is onCreate called again?

别来无恙 提交于 2019-12-18 11:27:23
问题 From my little android knowledge I understand that android OS can kill my service under extreme memory conditions. I have created a service that returns START_STICKY . The service is meant to run in background. If android is about to kill my service, will it call onDestroy ? And when it restarts it would it call onCreate ? 回答1: See here, the dev guide. http://developer.android.com/reference/android/app/Service.html#ProcessLifecycle onCreate() is only called when the process starts, which can

Android Pie (9.0) WebView in multi-process

最后都变了- 提交于 2019-12-18 10:54:36
问题 Starting Android Pie (API 28), Google isn't allowing using a single WebView instance in 2 different processes. Documentation: https://developer.android.com/reference/android/webkit/WebView.html#setDataDirectorySuffix(java.lang.String) As required, I called WebView.setDataDirectorySuffix("dir_name_no_separator") but unfortunately, I get an exception. I tried to call this method inside the 2nd process Service onCreate(). java.lang.RuntimeException: Unable to create service com.myapp.service

Android: Send e-mail with attachment automatically in the background [duplicate]

浪尽此生 提交于 2019-12-18 10:37:19
问题 This question already has answers here : Sending Email in Android using JavaMail API without using the default/built-in app (22 answers) Closed 6 years ago . I am making an app that allows the user to take a picture and send it automatically via email to the email he chooses. So far I was able to take a picture and store in the SD card. Now I only need functions that get the picture from the folder (/sdcard/Pictures/PhotoSender/) and send automatically to the e-mail the user has requested.

Using Job Scheduler in Android API <21

大兔子大兔子 提交于 2019-12-18 10:33:32
问题 I was looking at a scheduling tutorial by Vogella. It mentions the Job Scheduler API that was introduced in API 21 of Android. My question is can it be implemented in APIs lower than 21 (Lollipop) but not less than Android version 3 (Honeycomb)? 回答1: from now on (after I/O 2015), you can also use new GcmNetworkManager. How to use it and how it works is described here - https://developers.google.com/cloud-messaging/network-manager It does a lot cool stuff like it persists your tasks trough

How to use startForeground?

风格不统一 提交于 2019-12-18 09:36:52
问题 I have an android service, I am using startForeground, and do not get what I to expect to get. I use the following code: Intent intent = new Intent(this, MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pendIntent = PendingIntent.getActivity(this, 0, intent, 0); NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setContentTitle("TITLE").setContentText("CONTENT").setContentInfo("INFO") .setWhen

How to define started activity when relaunching Android application?

蓝咒 提交于 2019-12-18 09:17:43
问题 I am fairly new to Android, and am currently working on a simple XMPP Client. A user should be able to log in, and should be notified whenever an XMPP message arrives. It should be possible to access an overview of all messages that arrived during the current session. When launching the application, a LoginActivity is started, prompting the user to fill in his or her credentials. If the right credentials are provided, a background service is started: Intent intent = new Intent(this,

Getting a Handler from a Thread from Service to Activity

拜拜、爱过 提交于 2019-12-18 07:23:40
问题 Situation: activity binds to started foreground service. service hands out local binder to activity. activity gets reference to service through a getService() call. activity wants to communicate directly with a thread running in the service using messages. It calls the mService.getThreadHandler() method from the activity. Problem: how do I get a Handler from the current running thread into the active activity, so that I can post messages directly to the threads messagequeue? I don't what to

Are their any negatives impacts of launching two continues services at the same time? What are some alternatives if so?

与世无争的帅哥 提交于 2019-12-18 07:08:29
问题 I am planning on having an activity with two check boxes. I want to do some tasks when the screen is off in the background continuously based on what the user check marks. final CheckBox checkBox = (CheckBox) findViewById(R.id.checkbox_id); if ( checkBox1.isChecked() && myServiceIsntRunning() ) { startService(myService1.class) if ( checkBox2.isChecked() && myService2IsntRunning() ) { startService(myService2.class) } If both the checkmarks are checked, I wan't both tasks to constantly run in

AVD not running

十年热恋 提交于 2019-12-18 05:54:54
问题 Today when I was doing my project using android studio, a blue screen suddenly appears and system get restarted automatically. And now when I tried to run my app using emulator, the AVD is not running and I get an error as below. Anyone faced this before ? How do I fix this? ProcessNotCreatedException: Unexpected error while launching AVD: Cannot run program "C:\Users\tongws\AppData\Local\Android\sdk\tools\emulator.exe": CreateProcess error=216, This version of %1 is not compatible with the

Error calling toast from Service Android [duplicate]

折月煮酒 提交于 2019-12-18 04:16:09
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Android Toast started from Service only displays once I'm using Service Android defined in android.app.Service. I call this Service (myService) from an Activity. MyService is: public class myService extends Service{ public IBinder onBind(Intent intent){ return null; } public void onCreate(){ super.onCreate(); TimerTask task = new TimerTask(){ public void run(){ Log.i("test","service running"); checkDate(); } };