From: gumartinm Date: Tue, 6 Mar 2012 06:57:11 +0000 (+0100) Subject: I keep working on my Android service. X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=2ab8d196784e19db0406bbf4bcd19b9c2708a080;p=JavaForFun I keep working on my Android service. Implementing started and bound. --- diff --git a/Android/Testing/Test3/src/de/android/test3/NextActivity.java b/Android/Testing/Test3/src/de/android/test3/NextActivity.java index c85e353..e067aff 100644 --- a/Android/Testing/Test3/src/de/android/test3/NextActivity.java +++ b/Android/Testing/Test3/src/de/android/test3/NextActivity.java @@ -138,6 +138,15 @@ public class NextActivity extends Activity { Log.e(TAG, "Error while creating a URL", e); return; } + + + mCallbackText = new TextView(this); + this.doBindService(); + + + + + webServiceConnection = new MobieAdHttpClient(this.myCookie, url, httpClient, this, syncObject); this.exec.execute(webServiceConnection); @@ -148,8 +157,7 @@ public class NextActivity extends Activity { - mCallbackText = new TextView(this); - this.doBindService(); + } @@ -247,8 +255,9 @@ public class NextActivity extends Activity { // Establish a connection with the service. We use an explicit // class name because there is no reason to be able to let other // applications replace our component. - bindService(new Intent(NextActivity.this, + boolean prueba = bindService(new Intent(NextActivity.this, TestService.class), mConnection, Context.BIND_AUTO_CREATE); + System.out.print(prueba); mIsBound = true; mCallbackText.setText("Binding."); } diff --git a/Android/Testing/Test3/src/de/android/test3/TestService.java b/Android/Testing/Test3/src/de/android/test3/TestService.java index 4e6fe55..7ede7d9 100644 --- a/Android/Testing/Test3/src/de/android/test3/TestService.java +++ b/Android/Testing/Test3/src/de/android/test3/TestService.java @@ -3,7 +3,6 @@ package de.android.test3; import java.util.ArrayList; import android.app.Notification; import android.app.NotificationManager; -import android.app.PendingIntent; import android.app.Service; import android.content.Intent; import android.os.Handler; @@ -12,7 +11,6 @@ import android.os.Message; import android.os.Messenger; import android.os.RemoteException; import android.widget.Toast; -import android.app.Notification; public class TestService extends Service { @@ -91,6 +89,15 @@ public class TestService extends Service { } @Override + public int onStartCommand(Intent intent, int flags, int startId) { + + //Run the same code as MobieAdHttpclient.java + + // If we get killed, after returning from here, restart + return START_STICKY; + } + + @Override public void onDestroy() { // Cancel the persistent notification. mNM.cancel(R.string.remote_service_started); @@ -105,14 +112,6 @@ public class TestService extends Service { */ @Override public IBinder onBind(Intent intent) { - try { - synchronized (this) { - this.wait(10000); - } - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } return mMessenger.getBinder(); } @@ -139,5 +138,4 @@ public class TestService extends Service { // We use a string id because it is a unique number. We use it later to cancel. mNM.notify(R.string.remote_service_started, notification); } - }