Android Alert dialog from inside an intent service

Need Activity for display AlertDialog, because we can’t display Dialog from any Service Solution. Create Activity as Dialog Theme and start that Activity from Service. Just need to register you Activity in menifest.xml like as below android:theme=”@android:style/Theme.Dialog” or android:theme=”@android:style/Theme.Translucent.NoTitleBar” MyDialog.java public class MyDialog extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final AlertDialog … Read more

Proper way to stop IntentService

My problem is that I don’t know how/when to stop the service. IntentService automatically stops itself when onHandleIntent() ends, if no more commands had been sent to it while onHandleIntent() was running. Hence, you do not manually stop an IntentService yourself. When I call stopself() in onHandleIntent(Intent ..) all Intents which are waiting in the … Read more

send intent from service to activity

For this, you can use a BroadcastReceiver in your Activity. Here is a great example I use to communicate continuously between Service <> Activity using BroadcastReceivers. Here is another great example of communication between Service <> Activity. It uses Messenger and IncomingHandler. BroadcastReceiver I will make a quick example for your case. This is your … Read more

How is an Intent Service Declared in the Android Manifest?

In your manifest you declare a service with android:name=”.Communication”, this means that your service class should be located in com.exercise.AndroidClient.Communication Check that the packages are correct. Note that the “.” (dot) refers to the root of your package (ie the package declared in the manifest). So, for example, if your package is com.exercise.AndroidClient and your … Read more

How to force an IntentService to stop immediately with a cancel button from an Activity?

Here is the trick, make use of a volatile static variable and check continue condition in some of lines in your service that service continue should be checked: class MyService extends IntentService { public static volatile boolean shouldContinue = true; public MyService() { super(“My Service”); } @Override protected void onHandleIntent(Intent intent) { doStuff(); } private … Read more

Android: Using WebView outside an Activity context

You can display a webview from a service. Code below creates a window which your service has access to. The window isn’t visible because the size is 0 by 0. public class ServiceWithWebView extends Service { @Override public void onCreate() { super.onCreate(); WindowManager windowManager = (WindowManager) getSystemService(WINDOW_SERVICE); params = new WindowManager.LayoutParams(WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE, PixelFormat.TRANSLUCENT); … Read more

Android – Start service on boot

Well here is a complete example of an AutoStart Application AndroidManifest file <?xml version=”1.0″ encoding=”utf-8″?> <manifest xmlns:android=”http://schemas.android.com/apk/res/android” package=”pack.saltriver” android:versionCode=”1″ android:versionName=”1.0″> <uses-permission android:name=”android.permission.RECEIVE_BOOT_COMPLETED” /> <application android:icon=”@drawable/icon” android:label=”@string/app_name”> <receiver android:name=”.autostart”> <intent-filter> <action android:name=”android.intent.action.BOOT_COMPLETED” /> </intent-filter> </receiver> <activity android:name=”.hello”></activity> <service android:enabled=”true” android:name=”.service” /> </application> </manifest> autostart.java public class autostart extends BroadcastReceiver { public void onReceive(Context context, Intent arg1) … Read more