android:name=".list.MobiAdsNewAdsActivity"
android:theme="@android:style/Theme.Black"
android:screenOrientation="portrait"
- android:configChanges="touchscreen|keyboard" >
+ android:configChanges="touchscreen|keyboard"
+ android:noHistory="true"
+ android:taskAffinity="de.android.mobiads.list">
<intent-filter>
<action android:name="android.intent.action.MOBIADSNEWADS" />
<category android:name="android.intent.category.DEFAULT" />
package de.android.mobiads;
import android.app.Activity;
+import android.app.ActivityManager;
+import android.app.ActivityManager.RunningServiceInfo;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
public void onClickStartService(View v) {
- Intent intent = new Intent(MobiAdsMainActivity.this, MobiAdsService.class);
- intent.putExtra("cookie", MobiAdsMainActivity.cookie);
- this.startService(intent);
+ if (!this.isMyServiceRunning()) {
+ Intent intent = new Intent(MobiAdsMainActivity.this, MobiAdsService.class);
+ intent.putExtra("cookie", MobiAdsMainActivity.cookie);
+ this.startService(intent);
+ }
}
public void onClickListLocalAds(View v) {
intent.putExtra("login", false);
this.startActivity(intent);
}
+
+ private boolean isMyServiceRunning() {
+ ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
+ for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
+ if (MobiAdsService.class.getName().equals(service.service.getClassName())) {
+ return true;
+ }
+ }
+ return false;
+ }
}
CharSequence contentText;
if ((noReadCount = this.mobiAdsBatch.noReadAdsCount()) == 0) {
contentText = getText(R.string.remote_service_content_empty_notification);
+ showNotification(0, noReadCount, contentText, null);
}
else {
contentText = getText(R.string.remote_service_content_notification);
+ showNotification(0, noReadCount, contentText, MobiAdsNewAdsActivity.class);
}
- showNotification(0, noReadCount, contentText);
+
return super.onStartCommand(intent, flags, startId);
}
/**
* Show a notification while this service is running.
*/
- public void showNotification(final int level, final int noReadAds, CharSequence contentText) {
-
- Intent intent = new Intent(this, MobiAdsNewAdsActivity.class);
- 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, intent, PendingIntent.FLAG_UPDATE_CURRENT);
+ public void showNotification(final int level, final int noReadAds, CharSequence contentText, Class<?> cls) {
+ PendingIntent contentIntent = null;
+
+ if (cls != null) {
+ Intent intent = new Intent(this, MobiAdsNewAdsActivity.class);
+ intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
+ // The PendingIntent to launch our activity if the user selects this notification
+ contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
+ }
+
// Set the icon, scrolling text and timestamp
Notification.Builder notificationBuilder = new Notification.Builder(getApplicationContext()).
import android.util.Log;
import de.android.mobiads.MobiAdsService;
import de.android.mobiads.R;
+import de.android.mobiads.list.MobiAdsNewAdsActivity;
import de.android.mobiads.provider.Indexer;
public class MobiAdsBatch {
getText(R.string.remote_service_content_notification);
}
((MobiAdsService)MobiAdsBatch.this.context).
- showNotification(0, noReadCount, contentText);
+ showNotification(0, noReadCount, contentText, MobiAdsNewAdsActivity.class);
} catch (Throwable e1) {
//In case of any error, remove the index database and the file
public void showNotification(final int level, final int noReadAds, CharSequence contentText) {
NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
- Intent intent = new Intent(this, MobiAdsNewAdsActivity.class);
- 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, intent, PendingIntent.FLAG_UPDATE_CURRENT);
// Set the icon, scrolling text and timestamp
Notification.Builder notificationBuilder = new Notification.Builder(getApplicationContext()).
setWhen(System.currentTimeMillis()).
setContentText(contentText).
setContentTitle(getText(R.string.remote_service_title_notification)).
- setNumber(noReadAds).
- setContentIntent(contentIntent);
+ setNumber(noReadAds);
Notification notification = notificationBuilder.getNotification();
notification.flags |= Notification.FLAG_NO_CLEAR;
public void showNotification(final int level, final int noReadAds, CharSequence contentText) {
NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
- Intent intent = new Intent(this, MobiAdsNewAdsActivity.class);
- 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, intent, PendingIntent.FLAG_UPDATE_CURRENT);
// Set the icon, scrolling text and timestamp
Notification.Builder notificationBuilder = new Notification.Builder(getApplicationContext()).
setWhen(System.currentTimeMillis()).
setContentText(contentText).
setContentTitle(getText(R.string.remote_service_title_notification)).
- setNumber(noReadAds).
- setContentIntent(contentIntent);
+ setNumber(noReadAds);
Notification notification = notificationBuilder.getNotification();
notification.flags |= Notification.FLAG_NO_CLEAR;