Commit c008cc68 by Sebastián Katzer

Migrate from activity to service to handle the click events

parent 77c8ab29
......@@ -115,10 +115,8 @@
android:name="de.appplant.cordova.plugin.localnotification.ClearReceiver"
android:exported="false" />
<activity
<service
android:name="de.appplant.cordova.plugin.localnotification.ClickReceiver"
android:launchMode="singleInstance"
android:theme="@android:style/Theme.Translucent"
android:exported="false" />
<receiver
......
......@@ -353,7 +353,7 @@ public final class Builder {
int reqCode = random.nextInt();
PendingIntent contentIntent = PendingIntent.getActivity(
PendingIntent contentIntent = PendingIntent.getService(
context, reqCode, intent, FLAG_UPDATE_CURRENT);
builder.setContentIntent(contentIntent);
......@@ -403,8 +403,8 @@ public final class Builder {
int reqCode = random.nextInt();
return PendingIntent.getActivity(
context, reqCode, intent, FLAG_CANCEL_CURRENT);
return PendingIntent.getService(
context, reqCode, intent, FLAG_UPDATE_CURRENT);
}
/**
......
......@@ -21,7 +21,7 @@
package de.appplant.cordova.plugin.notification.receiver;
import android.app.Activity;
import android.app.IntentService;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
......@@ -38,16 +38,25 @@ import static de.appplant.cordova.plugin.notification.action.Action.EXTRA_ID;
* Abstract content receiver activity for local notifications. Creates the
* local notification and calls the event functions for further proceeding.
*/
abstract public class AbstractClickReceiver extends Activity {
abstract public class AbstractClickReceiver extends IntentService {
// Holds a reference to the intent to handle.
private Intent intent;
public AbstractClickReceiver() {
super("LocalNotificationClickReceiver");
}
/**
* Called when local notification was clicked to launch the main intent.
*/
@Override
protected void onResume() {
super.onResume();
protected void onHandleIntent(Intent intent) {
this.intent = intent;
if (intent == null)
return;
Intent intent = getIntent();
Bundle bundle = intent.getExtras();
Context context = getApplicationContext();
......@@ -61,7 +70,7 @@ abstract public class AbstractClickReceiver extends Activity {
return;
onClick(toast, bundle);
finish();
this.intent = null;
}
/**
......@@ -80,6 +89,13 @@ abstract public class AbstractClickReceiver extends Activity {
}
/**
* Getter for the received intent.
*/
protected Intent getIntent() {
return intent;
}
/**
* Launch main intent from package.
*/
protected void launchApp() {
......@@ -94,7 +110,8 @@ abstract public class AbstractClickReceiver extends Activity {
return;
intent.addFlags(
FLAG_ACTIVITY_REORDER_TO_FRONT | FLAG_ACTIVITY_SINGLE_TOP);
FLAG_ACTIVITY_REORDER_TO_FRONT
| FLAG_ACTIVITY_SINGLE_TOP);
context.startActivity(intent);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment