Android Phonegap application - bringing activity to the fore

I am participating in a learning process on how to work with Phonegap notifications on Android. Although displaying a notification seems like a fairly simple process

public void triggerTestNotification(String tag, int id,Context ctxt) 
{
  Intent notificationIntent = new Intent(context, PallActivity.class);
  notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | 
  Intent.FLAG_ACTIVITY_CLEAR_TOP);

  notificationIntent.setAction(Intent.ACTION_MAIN);
  notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);

  PendingIntent contentIntent = PendingIntent.getActivity(ctxt, 0,  
  notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

  Notification not = new Notification.Builder(ctxt)
  .setContentTitle("Title").setContentText("Title")
  .setTicker("Tick tock")
  .setAutoCancel(true) 
  .setContentIntent(contentIntent)
  .setSmallIcon(ctxt.getApplicationInfo().icon).build();
   NotificationManager notificationManager = (NotificationManager)    
   ctxt.getSystemService(Context.NOTIFICATION_SERVICE);
   notificationManager.notify(tag, id, not);
 }

what i found quite complicated is as follows

  • The user launches the application
  • The user leaves and starts to do something else - the application is conceived
  • A notification arrives.
  • Is displayed
  • The user clicks on the notification.

At this point, the application should return to the forefront. I thought my code of intent

public class PallActivity extends Activity
{
  @Override
  public void onCreate(Bundle savedInstanceState)
  {
   super.onCreate(savedInstanceState);
  finish();
  forceMainActivityReload();
 }

 private void forceMainActivityReload()
 {
  PackageManager pm = getPackageManager();
  Intent launchIntent =    
  pm.getLaunchIntentForPackage(getApplicationContext().getPackageName());           
  startActivity(launchIntent);
 }

 @Override
 protected void onResume() 
 {
  super.onResume();
  final NotificationManager notificationManager = (NotificationManager) 
  this.getSystemService(Context.NOTIFICATION_SERVICE);
  notificationManager.cancelAll();
 }

}

will do this, but he does nothing. It’s clear that I have something wrong here - perhaps in the flags of Intent. I would be very obliged to anyone who could put me on the right path

+4
1

finish(); oncreate, , .

PallActivity, , , , PallActivity . , forceMainActivityReload();. , , .

notification.flags = Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR;   
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

, :

Context context = getApplicationContext();

, , :

notificationIntent.setAction(Intent.ACTION_MAIN);
notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);

:

Android: ?

( )

Android:

, ?

+2

All Articles