Thursday 30 April 2015

Android Layout Finder & Code Generator

Hello Friends,

Today i found one tool which helps you create the code that ties your Android UI and Java code together.

It's real easy! Just paste your Android XML layout code in the first text field, pick the views that you need, and your code is automatically generated for you.
No more typing out all those nearly identical findViewById() and findFragmentById() calls in your activities or fragments whenever you change your Android layouts.

This is very helpful tool which reduces your efforts of initializing each views and declaring click events ,adapters,Viewholders etc. 

Check out Link HERE

Enjoy !!! 

Tuesday 28 April 2015

Sharing of Single & Multiple Images + Text using ACTION_SEND & ACTION_SEND_MULTIPLE Intent Services in AndroidMULTIPLE IMAGES + TEXT

Hello Friends,


    In android we can use the default share intent to share our image,text to an app installed in our device, but many times we only need specific application like Whatsapp, Facebook, Twitter, Gmail, etc. to be filtered out for sharing images + text. 

        Sometimes it happens that we want to share multiple images and text to share on a social apps like  Whatsapp, Facebook, Twitter, Gmail, etc. or may be on any application which are available in our device. 

So ,today i am going to show you the way to share SINGLE IMAGE + TEXT on a social media for particular application as well as all the social application in a device .

 And to share MULTIPLE IMAGES + TEXT on a social media for particular application as well as all the social application in a device .

So first of all i will show the code to share SINGLE IMAGE + TEXT on a social media.

Share single Image + Text using the Intent Services use the below code:
---------------------------------------------------------------------------------------------------------
       //Select a file from sdcard to share
       String fileName = "image-3116.jpg";//Name of an image
       String externalStorageDirectory = Environment.getExternalStorageDirectory().toString();
       String myDir = externalStorageDirectory + "/saved_images/"; // the file will be in saved_images
       Uri uri = Uri.parse("file:///" + myDir + fileName);

        Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
        shareIntent.setType("text/html");
        shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, (String) v.getTag(R.string.app_name));
        shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, (String) v.getTag(R.drawable.ic_launcher));
        shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
        startActivity(Intent.createChooser(shareIntent, "Share Deal"));

=====================================================================
To share the Image + Text on Single application like Facebook,Gmail,WhatsApp,Twitter for that below is the method 
=====================================================================

Select the image from the SDCard and convert it into an URI: 
---------------------------------------------------------------------------------------------------


 String fileName = "image-3116.jpg";

String externalStorageDirectory =    Environment.getExternalStorageDirectory().toString();
String myDir = externalStorageDirectory + "/saved_images/";
 // the file will be in saved_images
  Uri uri = Uri.parse("file:///" + myDir + fileName);
        


++++++++++++++++++++++++++++++
  Share via Twitter:
++++++++++++++++++++++++++++++

      Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
       shareIntent.setType("text/plain");
       shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, (String) v.getTag(R.string.app_name));
       shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, (String) v.getTag(R.drawable.ic_launcher));
        shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
   
       PackageManager pm = v.getContext().getPackageManager();
       List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0);
         for (final ResolveInfo app : activityList) 
          {
            if ("com.twitter.android.PostActivity".equals(app.activityInfo.name))
              {
                 final ActivityInfo activity = app.activityInfo;
                 final ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name);
                 shareIntent.addCategory(Intent.CATEGORY_LAUNCHER);
                 shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
                 shareIntent.setComponent(name);
                 v.getContext().startActivity(shareIntent);
                break;
              }
            }

++++++++++++++++++++++++++++++
   Share via Facebook:
++++++++++++++++++++++++++++++

       Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
       shareIntent.setType("text/plain");
       shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, (String) v.getTag(R.string.app_name));
       shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, (String) v.getTag(R.drawable.ic_launcher));
       shareIntent.putExtra(Intent.EXTRA_STREAM, uri);

       PackageManager pm = v.getContext().getPackageManager();
       List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0);
         for (final ResolveInfo app : activityList) 
         {
             if ((app.activityInfo.name).contains("facebook")) 
             {
               final ActivityInfo activity = app.activityInfo;
               final ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name);
              shareIntent.addCategory(Intent.CATEGORY_LAUNCHER);
              shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
              shareIntent.setComponent(name);
              v.getContext().startActivity(shareIntent);
              break;
            }
          }

++++++++++++++++++++++++++++++
    Share via Gmail:
++++++++++++++++++++++++++++++

      Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
    shareIntent.setType("text/plain");
    shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, (String) v.getTag(R.string.app_name));
    shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, (String) v.getTag(R.drawable.ic_launcher));
    shareIntent.putExtra(Intent.EXTRA_STREAM, uri);

    PackageManager pm = v.getContext().getPackageManager();
    List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0);
         for (final ResolveInfo app : activityList) 
          {
            if ((app.activityInfo.name).contains("android.gm")) 
             {
               final ActivityInfo activity = app.activityInfo;
               final ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name);
             shareIntent.addCategory(Intent.CATEGORY_LAUNCHER);
             shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
              shareIntent.setComponent(name);
              v.getContext().startActivity(shareIntent);
                break;
             }
           }

++++++++++++++++++++++++++++++  
    Share via WhatsApp:
++++++++++++++++++++++++++++++

    Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
  shareIntent.setType("text/html");
  shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, (String) v.getTag(R.string.app_name));
  shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, (String) v.getTag(R.drawable.ic_launcher));
  shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
     
  PackageManager pm = v.getContext().getPackageManager();
  List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0);
  for (final ResolveInfo app : activityList) {
    if ((app.activityInfo.name).contains("com.whatsapp")) {
        final ActivityInfo activity = app.activityInfo;
    final ComponentName name = new ComponentName(
    activity.applicationInfo.packageName, activity.name);
  shareIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); 
shareIntent.setComponent(name);
     v.getContext().startActivity(shareIntent);
break;
    }
    }



+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Now if you want to share multiple Images using Intent Services use the below code which selects multiple images from one of the folder from the sdcard and adds images into an ArrayList<Uri> and pass it into the stream: 
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

 //Select one folder from the sdcard and get all the images from it.
String externalStorageDirectory = Environment.getExternalStorageDirectory().toString();

// the files will be in saved_images folder. You can change it according to your folder name.
String myDir = externalStorageDirectory + "/saved_images/";


 //Filter only images from the folder.
FilenameFilter m_filter = new FilenameFilter() {
@Override
public boolean accept(File dir, String filename) {
if (filename.endsWith(".jpeg") || filename.endsWith(".jpg")|| filename.endsWith(".png")) {
return true;
        }
        return false;
}
};
ArrayList<Uri> Imageuris = new ArrayList<Uri>();
File m_file = new File(myDir);
if (m_file.isDirectory()) {
for (File f : m_file.listFiles(m_filter)) {
Uri uri = Uri.parse("file:///" + f.getAbsolutePath().toString());
Imageuris.add(uri);
}
}


++++++++++++++++++++++++++++++
    Share via Gmail:
++++++++++++++++++++++++++++++

Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
shareIntent.setType("text/html");
shareIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { "to" });
shareIntent.putExtra(Intent.EXTRA_STREAM, Imageuris);
  shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,(String) v.getTag(R.string.app_name));
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT,(String) v.getTag(R.drawable.ic_launcher));
                       
PackageManager pm = v.getContext().getPackageManager();
List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0);
for (final ResolveInfo app : activityList) {
if ((app.activityInfo.name).contains("android.gm")) {
final ActivityInfo activity = app.activityInfo;
final ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name);
shareIntent.addCategory(Intent.CATEGORY_LAUNCHER);
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
shareIntent.setComponent(name);
v.getContext().startActivity(shareIntent);
break;
          }
}


++++++++++++++++++++++++++++++
   Share via Facebook:
++++++++++++++++++++++++++++++

 Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
shareIntent.setType("text/html");
shareIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { "to" });
shareIntent.putExtra(Intent.EXTRA_STREAM, Imageuris);
  shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,(String) v.getTag(R.string.app_name));
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT,(String) v.getTag(R.drawable.ic_launcher));
                       
PackageManager pm = v.getContext().getPackageManager();
List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0);
for (final ResolveInfo app : activityList) {
if ((app.activityInfo.name).contains("facebook")) {
final ActivityInfo activity = app.activityInfo;
final ComponentName name = new ComponentName(
activity.applicationInfo.packageName, activity.name);
shareIntent.addCategory(Intent.CATEGORY_LAUNCHER);
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
     | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
shareIntent.setComponent(name);
v.getContext().startActivity(shareIntent);
    break;
}
}

++++++++++++++++++++++++++++++  
    Share via WhatsApp:
++++++++++++++++++++++++++++++

Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
shareIntent.setType("text/html");
shareIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { "to" });
shareIntent.putExtra(Intent.EXTRA_STREAM, Imageuris);
  shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,(String) v.getTag(R.string.app_name));
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT,(String) v.getTag(R.drawable.ic_launcher));
                       
PackageManager pm = v.getContext().getPackageManager();
List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0);
for (final ResolveInfo app : activityList) {
   if ((app.activityInfo.name).contains("com.whatsapp")) {
final ActivityInfo activity = app.activityInfo;
final ComponentName name = new ComponentName(
activity.applicationInfo.packageName, activity.name);
shareIntent.addCategory(Intent.CATEGORY_LAUNCHER);
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
shareIntent.setComponent(name);
v.getContext().startActivity(shareIntent);
break;
}
}


++++++++++++++++++++++++++++++
  Share via Twitter:
++++++++++++++++++++++++++++++

 Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
shareIntent.setType("text/html");
shareIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { "to" });
shareIntent.putExtra(Intent.EXTRA_STREAM, Imageuris);
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,(String) v.getTag(R.string.app_name));
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT,(String) v.getTag(R.drawable.ic_launcher));
                       
PackageManager pm = v.getContext().getPackageManager();
List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0);
for (final ResolveInfo app : activityList) {
  if((app.activityInfo.name).contains("com.twitter.android.PostActivity")) {
final ActivityInfo activity = app.activityInfo;
final ComponentName name = new ComponentName(
  activity.applicationInfo.packageName, activity.name);
shareIntent.addCategory(Intent.CATEGORY_LAUNCHER);
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
shareIntent.setComponent(name);
v.getContext().startActivity(shareIntent);
           break;
     }
}

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Lastly to share multiple Images + Text on any Social media besides specifying any fix application you can use the below code which do not filters an application from the device and provides list of all the shareable apps from the device.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
  shareIntent.setType("text/html");
  shareIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { "to" });
  shareIntent.putExtra(Intent.EXTRA_STREAM, Imageuris);
  shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,(String) v.getTag(R.string.app_name));
  shareIntent.putExtra(android.content.Intent.EXTRA_TEXT,(String)v.getTag(R.drawable.ic_launcher));
  startActivity(shareIntent);


Also you can help out to improve it more. 
I Hope this will help a lot !!

Enjoy!! 

Friday 24 April 2015

Capture the whole ListView and create an image ,Even if the whole part of it is not visible on the screen.

Hello Friends,

          Today i have done some new research on how can we capture an Image of the whole ListView even the whole items of listview are not visible on screen and save it as a bitmap even though all the items of the ListView are not visible on the screen.

I have made a simple method which gives you image of the listview.

So here i am going to show you the code to capture the listview and save it as an image into the SDcard.

You can use the below code in your application directly.
Here is the method which captures your whole ListView and convert it into the Bitmap.

  /**  
  * Take a screenshot of a whole listview even if the whole listview elements  
  * aren't fully visible in the screen  
  *   
  * @param p_ListView  
  *      -ListView instance  
  * @return-Bitmap of List  
  */  
  public void getWholeListViewItemsToBitmap(ListView p_ListView) {  
   ListView listview = p_ListView;  
  ListAdapter adapter = listview.getAdapter();  
  int itemscount = adapter.getCount();  
  int allitemsheight = 0;  
  List<Bitmap> bmps = new ArrayList<Bitmap>();  
   for (int i = 0; i < itemscount; i++) {  
   View childView = adapter.getView(i, null, listview);  
   childView.measure(  
    MeasureSpec.makeMeasureSpec(listview.getWidth(), MeasureSpec.EXACTLY),  
    MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));  
   childView.layout(0, 0, childView.getMeasuredWidth(), childView.getMeasuredHeight());  
   childView.setDrawingCacheEnabled(true);  
   childView.buildDrawingCache();  
   bmps.add(childView.getDrawingCache());  
   allitemsheight += childView.getMeasuredHeight();  
  }  
   Bitmap bigbitmap = Bitmap.createBitmap(listview.getMeasuredWidth(), allitemsheight,  
   Bitmap.Config.ARGB_8888);  
  Canvas bigcanvas = new Canvas(bigbitmap);  
   Paint paint = new Paint();  
  int iHeight = 0;  
   for (int i = 0; i < bmps.size(); i++) {  
   Bitmap bmp = bmps.get(i);  
   bigcanvas.drawBitmap(bmp, 0, iHeight, paint);  
   iHeight += bmp.getHeight();  
   bmp.recycle();  
   bmp = null;  
  }  
  storeImage(bigbitmap, "Test.jpg");  
  }  
  /**  
  * Convert the bitmap into image and save it into the sdcard.  
  *   
  * @param imageData  
  *      -Bitmap image.  
  * @param filename  
  *      -Name of the image.  
  * @return  
  */  
  public boolean storeImage(Bitmap imageData, String filename) {  
  // get path to external storage (SD card)  
  File sdIconStorageDir = new File(Environment.getExternalStorageDirectory()  
   .getAbsolutePath() + "/myAppDir/");  
   // create storage directories, if they don't exist  
  sdIconStorageDir.mkdirs();  
   try {  
   String filePath = sdIconStorageDir.toString() + File.separator + filename;  
   FileOutputStream fileOutputStream = new FileOutputStream(filePath);  
   BufferedOutputStream bos = new BufferedOutputStream(fileOutputStream);  
   Toast.makeText(m_cont, "Image Saved at----" + filePath, Toast.LENGTH_LONG).show();  
   // choose another format if PNG doesn't suit you  
   imageData.compress(CompressFormat.PNG, 100, bos);  
   bos.flush();  
   bos.close();  
   } catch (FileNotFoundException e) {  
   Log.w("TAG", "Error saving image file: " + e.getMessage());  
   return false;  
  } catch (IOException e) {  
   Log.w("TAG", "Error saving image file: " + e.getMessage());  
   return false;  
  }  
   return true;  
  }  

Here is the activity code which shows how you can use the above methods in your application.
I have called a method onClick of Button to generate image.
 public class SimpleListViewActivity extends Activity {  
  private ListView mainListView;  
  private ArrayAdapter<String> listAdapter;  
  /** Called when the activity is first created. */  
  @Override  
  public void onCreate(Bundle savedInstanceState) {  
  super.onCreate(savedInstanceState);  
  setContentView(R.layout.main);  
   // Find the ListView resource.  
  mainListView = (ListView) findViewById(R.id.mainListView);  
   // Create and populate a List of planet names.  
  String[] planets = new String[] { "Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn",  
   "Uranus", "Neptune", "Solar", "Pluto","Ceres","Haumea","Makemake","Eris" };  
  ArrayList<String> planetList = new ArrayList<String>();  
  planetList.addAll(Arrays.asList(planets));  
   // Create ArrayAdapter using the planet list.  
  listAdapter = new ArrayAdapter<String>(this, R.layout.simplerow, planetList);  
   // Set the ArrayAdapter as the ListView's adapter.  
  mainListView.setAdapter(listAdapter);  
  findViewById(R.id.button1).setOnClickListener(new OnClickListener() {  
   @Override  
   public void onClick(View v) {  
   getWholeListViewItemsToBitmap(mainListView);  
   }  
  });  
  }  

Layout file of an activity
 <?xml version="1.0" encoding="utf-8"?>  
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
   android:layout_width="fill_parent"  
   android:layout_height="fill_parent"  
   android:orientation="vertical" >  
   <Button  
     android:id="@+id/button1"  
     android:layout_width="wrap_content"  
     android:layout_height="wrap_content"  
     android:text="Capture Screen"  
     android:visibility="visible" />  
   <ListView  
     android:id="@+id/mainListView"  
     android:layout_width="fill_parent"  
     android:layout_height="fill_parent"  
     android:background="@android:color/white"  
     android:listSelector="@null" >  
   </ListView>  
 </LinearLayout>  

Let me know if anyone facing any problem or any kind of improvement needed.

Thank you. 
Enjoy !!!




Sunday 19 April 2015

Facing problem on Upload Large Size Video on the Server using the Multipart entity in Android

Hello Friends,

         While developing any application's which contains the functionality like uploading large sizes of images as well as the videos ,we are always facing problem of OutOfMemory in android.

Today i am going to share my knowledge with you about an uploading the large video's on server which i recently faced in one of application. The uploading video was working fine if the video size is less than 16MB. But as it increases the OutOfMemory problem started occurring.]
So after doing the research on it i found solution of it which you can use.

Solution 1: 
 HttpURLConnection m_httpconnection = null;  
 m_httpconnection = (HttpURLConnection) new URL(m_wsUrl).openConnection();  m_httpconnection.setConnectTimeout(2000);  
         m_httpconnection.setDoInput(true);  
         m_httpconnection.setDoOutput(true);  
         m_httpconnection.setUseCaches(false);  
 m_httpconnection.setChunkedStreamingMode(1024);   
 m_httpconnection.setRequestMethod("POST");  
 m_httpconnection.setRequestProperty("Connection", "Keep-Alive");  
 m_httpconnection.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + BOUNDARY);  
In the above solution I have used method  setChunkedStreamingMode(1024), which will help you chunk your whole data into specific size so that you do not need to keep your entire file in memory.

You can also use  m_httpConnection.setFixedLengthStreamingMode(1024);  method if the length of HTTP request body is known ahead. It sets fixed length to enable streaming without buffering. Sets after connection will cause an exception.

Thank you.

Tuesday 7 April 2015

A Pitfall in PendingIntent and Its Solution

Hello Friends,

              The Android documentation has a nice overview chapter about how to notifiy the user with status bar notifications. The example text works quite nicely and the user gets informed and can then call back into the application. 
Setting up a notification goes along the lines of (taken from the developer guide):

 Intent notificationIntent = new Intent(this, MyClass.class);  
 PendingIntent contentIntent= PendingIntent.getActivity(this,0, notificationIntent, 0);  
 notification.setLatestEventInfo(context, "Title","something went wrong", contentIntent);  

    where a PendingIntent is set up as a "pointer" and stored by the system so that when the user selects the notification in the status bar the target activity specified in the notificationIntent can be called. 
Now sometimes you want to attach some additional data to the intent to be delivered - like a longer explanation why your action failed. You would go like:

 Intent notificationIntent = new Intent(context,MyClass.class);  
  notificationIntent.putExtra("key","value");      
  notificationIntent.putExtra("key2",someCounter++);   

  to add the payload. And in MyClass you would get the data via

 Intent intent = getIntent();      
 Bundle bundle = intent.getExtras();      
 String head = bundle.getString("key");      
 Integer body = bundle.getInt("key2");  

 Now when the notification fires,  the intent is created and attached to the PendingIntent and this shows up in the status bar.

User then selects the status bar to see the longer message and presses this area to see the full details. This means that the system delivers "out of the blue" the created Intent message and thus starts MyClass-activity, which then pulls the payload from the intent. 

When you do this a few times in a row you will see that the passed counter (someCounter) does increase in your sending activity, but that the receiver always shows the initial value. Canceling the notification in the sender does not help here. 

This comes from the fact, that the system does not assume that only because we pass a new Intent object to the pending intent, we want this new intent object to be delivered and just keeps the old (initial) pending intent alive.
To get the desired semantics, we need to pass a flag to tell the system:
 PendingIntent pintent =  PendingIntent.getActivity(context,0,intent,PendingIntent.FLAG_CANCEL_CURRENT);  

This flag (FLAG_CANCEL_CURRENT) tells the system that the old pending intent is no longer valid and it should cancel (=remove) it and then create a fresh one for us.

There are more possible flags, which are described on the javadoc page for PendingIntent.


Thanks,