Latest changes in Android Test3 application.
authorgumartinm <gu.martinm@gmail.com>
Mon, 19 Mar 2012 23:05:06 +0000 (00:05 +0100)
committergumartinm <gu.martinm@gmail.com>
Mon, 19 Mar 2012 23:05:06 +0000 (00:05 +0100)
Next step: implement my MobiAds Android application.

Android/Testing/Test3/AndroidManifest.xml
Android/Testing/Test3/gen/de/android/test3/R.java
Android/Testing/Test3/res/layout/nextactivity.xml
Android/Testing/Test3/res/values/strings.xml
Android/Testing/Test3/src/de/android/test3/MobieAdHttpClient.java
Android/Testing/Test3/src/de/android/test3/NextActivity.java
Android/Testing/Test3/src/de/android/test3/Test3Activity.java
Android/Testing/Test3/src/de/android/test3/TestService.java

index 2ecb907..fdf4d3e 100644 (file)
@@ -26,7 +26,7 @@
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
         </activity>
-        
+               
         <activity 
                        android:label="@string/app_name"
                        android:name=".NextActivity" 
@@ -35,7 +35,7 @@
                        android:configChanges="touchscreen|keyboard" 
                        android:permission="android.permission.INTERNET">
             <intent-filter>
-                <action android:name="android.intent.action.RUN"/>
+                <action android:name="android.intent.action.MOBIADS"/>
                 <category android:name="android.intent.category.DEFAULT" />
             </intent-filter>
                </activity>
                <service
                    android:name=".TestService"
                android:process=":testservice" >
-            <intent-filter>
-                <action android:name="android.intent.action.RUN"/>
-                <category android:name="android.intent.category.DEFAULT" />
-            </intent-filter>
         </service>
                
     </application>
index 8659e5d..b54b83c 100644 (file)
@@ -29,16 +29,20 @@ public final class R {
     public static final class string {
         public static final int alert_dialog_cancel=0x7f040000;
         public static final int app_name=0x7f040004;
-        public static final int button_cancel=0x7f040009;
+        public static final int button_cancel=0x7f04000d;
         public static final int button_login=0x7f040007;
-        public static final int button_ok=0x7f040008;
+        public static final int button_messagebind=0x7f040008;
+        public static final int button_messagestartservice=0x7f04000b;
+        public static final int button_messagestopservice=0x7f04000a;
+        public static final int button_messageunbind=0x7f040009;
+        public static final int button_ok=0x7f04000c;
         public static final int error_dialog_connection_error=0x7f040001;
         public static final int error_dialog_userpwd_error=0x7f040002;
         public static final int hello=0x7f040003;
         public static final int password=0x7f040006;
-        public static final int remote_service_label=0x7f04000c;
-        public static final int remote_service_started=0x7f04000a;
-        public static final int remote_service_stopped=0x7f04000b;
+        public static final int remote_service_label=0x7f040010;
+        public static final int remote_service_started=0x7f04000e;
+        public static final int remote_service_stopped=0x7f04000f;
         public static final int username=0x7f040005;
     }
 }
index 5203a2b..9b4f8e3 100644 (file)
@@ -9,5 +9,52 @@
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:text="@string/hello" />
-    
+    <FrameLayout 
+       android:id="@+id/frameLayout1" 
+       android:layout_width="match_parent" 
+       android:layout_height="30dp">
+    </FrameLayout>
+    <Button
+               android:id="@+id/login_button"
+               android:onClick="onClickMessage"
+           android:layout_height="wrap_content" 
+           android:text="@string/button_messagebind" 
+           android:layout_width="match_parent" 
+           android:layout_gravity="center"/>
+    <FrameLayout 
+       android:id="@+id/frameLayout1" 
+       android:layout_width="match_parent" 
+       android:layout_height="30dp">
+    </FrameLayout>
+    <Button
+               android:id="@+id/login_button"
+               android:onClick="onClickUnBind"
+           android:layout_height="wrap_content" 
+           android:text="@string/button_messageunbind" 
+           android:layout_width="match_parent" 
+           android:layout_gravity="center"/>
+    <FrameLayout 
+       android:id="@+id/frameLayout1" 
+       android:layout_width="match_parent" 
+       android:layout_height="30dp">
+    </FrameLayout>
+    <Button
+               android:id="@+id/login_button"
+               android:onClick="onClickStopService"
+           android:layout_height="wrap_content" 
+           android:text="@string/button_messagestopservice" 
+           android:layout_width="match_parent" 
+           android:layout_gravity="center"/>
+    <FrameLayout 
+       android:id="@+id/frameLayout1" 
+       android:layout_width="match_parent" 
+       android:layout_height="30dp">
+    </FrameLayout>
+    <Button
+               android:id="@+id/login_button"
+               android:onClick="onClickStartService"
+           android:layout_height="wrap_content" 
+           android:text="@string/button_messagestartservice" 
+           android:layout_width="match_parent" 
+           android:layout_gravity="center"/>  
 </LinearLayout>
\ No newline at end of file
index 055a1ca..0198c8c 100644 (file)
@@ -9,11 +9,15 @@
     <string name="error_dialog_userpwd_error">
         The username or password you entered is incorrect.
     </string>
-    <string name="hello">Hello World, Test3Activity!</string>
+    <string name="hello">Hello World, NextActivity!</string>
     <string name="app_name">Test3</string>
     <string name="username">Username</string>
     <string name="password">Password</string>
     <string name="button_login">Log In</string>
+    <string name="button_messagebind">Bind Service</string>
+    <string name="button_messageunbind">Unbind Service</string>
+    <string name="button_messagestopservice">Stop Service</string>
+    <string name="button_messagestartservice">Start Service</string>
     <string name="button_ok">OK</string>
     <string name="button_cancel">Cancel</string>
     <string name="remote_service_started">Remote Service Started</string>
index 4b07a6d..a243054 100644 (file)
@@ -111,6 +111,16 @@ public class MobieAdHttpClient implements Runnable
                                                           }
                                                           
                                                           //Besides throw the original exception.
+                                                          if (e1 instanceof Error) {
+                                                                       throw (Error) e1;
+                                                          }
+                                                          if (e1 instanceof RuntimeException) {
+                                                                       throw (RuntimeException) e1;
+                                                          }
+                                                          if (e1 instanceof Exception) {
+                                                                  throw (IOException) e1;
+                                                          }
+                                                          //throwing Throwable. At least the original exception is not lost :/
                                                           throw e1;
                                                   }  
                                           }
index ed3e7e4..3c873e0 100644 (file)
@@ -23,6 +23,7 @@ import android.os.Message;
 import android.os.Messenger;
 import android.os.RemoteException;
 import android.util.Log;
+import android.view.View;
 import android.webkit.CookieManager;
 import android.webkit.CookieSyncManager;
 import android.widget.TextView;
@@ -120,7 +121,10 @@ public class NextActivity extends Activity {
         locationManager.requestLocationUpdates(0, 10, criteria, locationListener, null);
         
         
-        
+        //Al parecer si pongo esto aqui, el servicio es enlazado nada mas iniciarse la aplicacion 
+        //incluso cuando todavia estoy en la activity que hace login (la Test3Activity)
+        //¿Se lanza el onCreate de una activity incluso antes de usar esa activity? ¿Por qué?
+        //¿Quizás porque está declarada en el Manifest?
         //mCallbackText = new TextView(this);
                //this.doBindService();
     }
@@ -249,4 +253,23 @@ public class NextActivity extends Activity {
         mCallbackText.setText("Binding.");
     }
 
+    
+    public void onClickMessage(View v) {
+       mCallbackText = new TextView(this);
+               this.doBindService();
+    }
+    
+    
+    public void onClickUnBind(View v) {
+       this.unbindService(mConnection);
+    }
+    
+    public void onClickStopService(View v) {
+       this.stopService(new Intent(NextActivity.this, TestService.class));
+    }
+    
+    
+    public void onClickStartService(View v) {
+       this.startService(new Intent(NextActivity.this, TestService.class));
+    }
 }
index 87fc810..32ca947 100644 (file)
@@ -90,12 +90,8 @@ public class Test3Activity extends Activity {
                                        CookieSyncManager.getInstance().sync();
                                        //Go to the next activity
                                        StrictMode.setThreadPolicy(currentPolicy);
-//                                     this.startService(new Intent(Test3Activity.this, TestService.class));
-//                                     this.startActivity(new Intent(Intent.ACTION_RUN).
-//                                                     setComponent(new ComponentName("de.android.test3", "de.android.test3.NextActivity")));
-                                       this.startService(new Intent(Intent.ACTION_RUN).
-                                                       setComponent(new ComponentName("de.android.test3", "de.android.test3.TestService")));
-                                       this.finish();
+                                       this.startActivity(new Intent(Intent.ACTION_RUN).
+                                                       setComponent(new ComponentName("de.android.test3", "de.android.test3.NextActivity")));
                        } else {
                                Log.e(TAG, "There must be a weird issue with the server because... There is not cookie!!!!");
                                createErrorDialog(R.string.error_dialog_connection_error);
index 3de07fc..128b0a7 100644 (file)
@@ -12,6 +12,7 @@ import android.os.IBinder;
 import android.os.Message;
 import android.os.Messenger;
 import android.os.RemoteException;
+import android.util.Log;
 import android.widget.Toast;
 
 public class TestService extends Service {
@@ -85,7 +86,7 @@ public class TestService extends Service {
     @Override
     public void onCreate() {
         mNM = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
-
+        Log.i("servicio", "onCreate");
         // Display a notification about us starting.
         showNotification();
     }
@@ -94,7 +95,7 @@ public class TestService extends Service {
     public int onStartCommand(Intent intent, int flags, int startId) {
        
        //Run the same code as MobieAdHttpclient.java
-       
+       Log.i("servicio", "onStartCommand");
        // If we get killed, after returning from here, restart
        return START_STICKY;
     }
@@ -114,6 +115,7 @@ public class TestService extends Service {
      */
     @Override
     public IBinder onBind(Intent intent) {
+       Log.i("servicio", "onBind");
         return mMessenger.getBinder();
     }
 
@@ -127,19 +129,24 @@ public class TestService extends Service {
         // Set the icon, scrolling text and timestamp
         Notification notification = new Notification(R.drawable.alert_dialog_icon, text, System.currentTimeMillis());
 
+        Intent intent =  new Intent(this, NextActivity.class);
+        //Intent intent = new Intent(Intent.ACTION_RUN).setComponent(new ComponentName("de.android.test3", "de.android.test3.WelcomeActivity"));
+        //intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
         // The PendingIntent to launch our activity if the user selects this notification
-        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, NextActivity.class), 0);
+        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
+        
 
         Context context = getApplicationContext();
 
+        notification.contentIntent = contentIntent;
         // Set the info for the views that show in the notification panel.
-        notification.setLatestEventInfo(context, getText(R.string.remote_service_label), text, contentIntent);
         notification.defaults |= Notification.DEFAULT_VIBRATE;
         notification.ledARGB = 0xff00ff00;
         notification.ledOnMS = 300;
         notification.ledOffMS = 1000;
         notification.flags |= Notification.FLAG_SHOW_LIGHTS;
-
+        //notification.flags |= Notification.FLAG_AUTO_CANCEL;
+        notification.setLatestEventInfo(context, getText(R.string.remote_service_label), text, contentIntent);
 
         // Send the notification.
         // We use a string id because it is a unique number.  We use it later to cancel.