Next step: implement my MobiAds Android application.
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
-
+
<activity
android:label="@string/app_name"
android:name=".NextActivity"
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>
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;
}
}
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
<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>
}
//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;
}
}
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;
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();
}
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));
+ }
}
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);
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 {
@Override
public void onCreate() {
mNM = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
-
+ Log.i("servicio", "onCreate");
// Display a notification about us starting.
showNotification();
}
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;
}
*/
@Override
public IBinder onBind(Intent intent) {
+ Log.i("servicio", "onBind");
return mMessenger.getBinder();
}
// 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.