Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9157421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:00:46+00:00 2026-06-17T13:00:46+00:00

I have implemented push notification using GCM for my android app. Now i am

  • 0

I have implemented push notification using GCM for my android app. Now i am getting the notification for all the registered device. But I am confused when should I unregistered my device.

MainActivity.java

public class DemoActivity extends Activity {

    TextView mDisplay;
    private String TAG = "** Demo Activity Push **";

    public final String SOAP_ACTION4 = "http://tempuri.org/InsertDeviceID";
    public final String OPERATION_NAME4 = "InsertDeviceID"; 
    public final String WSDL_TARGET_NAMESPACE4 = "http://tempuri.org/";
    public final String SOAP_ADDRESS4 = "http://www.icecup.com/iphonews/pushnotification.asmx"; 

    String regId ;
    String receivedString;
    String delreceivedString;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);



        checkNotNull(SENDER_ID, "SENDER_ID");

        GCMRegistrar.checkDevice(getApplicationContext()); 
        GCMRegistrar.checkManifest(getApplicationContext());
           setContentView(R.layout.main);
        mDisplay = (TextView) findViewById(R.id.display);     
        regId = GCMRegistrar.getRegistrationId(getApplicationContext());
        if (regId.equals("")) {
            // Automatically registers application on startup.
            GCMRegistrar.register(getApplicationContext(), SENDER_ID);
        } else {
        Log.v(TAG, "Already registered");           
        }
       mDisplay.setText("ffffff        "+regId);
     //   setDeviceRegId(regId);
       // new MovieDetails().execute(regId);
       try {
            Class.forName("android.os.AsyncTask");
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } 
    }

    public class MovieDetails extends AsyncTask<String, Void, Void> {

        @Override
        protected  Void doInBackground(String... params) {          

            String parregid= params[0];
            Log.d("DEVICE REG ID", parregid);
            SoapObject request99 = new SoapObject(WSDL_TARGET_NAMESPACE4,OPERATION_NAME4);
            request99.addProperty("DeviceId",parregid);
            System.out.println("I AM ALIVE 1");
                SoapSerializationEnvelope envelope99 = new SoapSerializationEnvelope(
                        SoapEnvelope.VER11);

                envelope99.dotNet = true;

                envelope99.setOutputSoapObject(request99);
                System.out.println("I AM ALIVE 2");
                HttpTransportSE httpTransport99 = new HttpTransportSE(SOAP_ADDRESS4);
                System.out.println("I AM ALIVE 3");             
                SoapPrimitive  response=null;
                try {
                    httpTransport99.call(SOAP_ACTION4, envelope99);
                    System.out.println("I AM ALIVE 4");
                    response = (SoapPrimitive) envelope99.getResponse();    
                    System.out.println("I AM ALIVE 5");
                    System.out.println("RESPONSE IS:  "+response.toString());   
                    receivedString=response.toString();
                } catch (Exception e) {
                }
                return null;
        }

        @Override
        protected void onCancelled()
        {
            super.onCancelled();
        }

        @Override
        protected void onPreExecute() {

            System.out.println("I AM ALIVE 0");
        }

        @Override
        protected void onPostExecute( Void result) {        

            System.out.println(" RESPONSE "+receivedString);
            super.onPostExecute(result);
        }


    }

    private final BroadcastReceiver mHandleMessageReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String newMessage = intent.getExtras().getString("message");
            // Waking up mobile if it is sleeping
            WakeLocker.acquire(getApplicationContext());            

            mDisplay.append(newMessage + "\n");         
            Toast.makeText(getApplicationContext(), "New Message: " + newMessage, Toast.LENGTH_LONG).show();            
            WakeLocker.release();
        }
    };

    @Override
    protected void onDestroy() {

        try {
            unregisterReceiver(mHandleMessageReceiver);
             GCMRegistrar.onDestroy(getApplicationContext());

        } catch (Exception e) {
            Log.e("UnRegister Receiver Error", "> " + e.getMessage());
        }
        super.onDestroy();
    }

    private void checkNotNull(Object reference, String name) {
        if (reference == null) {
            throw new NullPointerException(
                    getString(R.string.error_config, name));
        }
    }
}

This is my main activity. Tell me where should I call GCM.Unregister(this) . Because if someone uninstall the app, for that registration id GCM server sends response NotRegistered to 3rd party server. So keeping that in mind I was thinking to unregister the device.

GCMIntentService.java

public class GCMIntentService extends GCMBaseIntentService {


    private static final String TAG = "GCMIntentService";
    String installregids = "";
    String uninstallregids = "";
    DemoActivity dact= new DemoActivity();

    public GCMIntentService() {
        super(SENDER_ID);
    }

    @Override
    protected void onRegistered(Context context, String registrationId) {
        Log.i(TAG, "Device registered: regId = " + registrationId);        

        this.installregids=registrationId;
         try {
        dact.new MovieDetails().execute(registrationId); 


           GCMRegistrar.setRegisteredOnServer(context, true);
         }
         catch (Exception e) {
             e.printStackTrace();
         }
    }

    @Override
    protected void onUnregistered(Context context, String registrationId) {
        Log.i(TAG, "Device unregistered");

        this.uninstallregids=registrationId; 
         try {
             if (GCMRegistrar.isRegisteredOnServer(context)) {
            //  dact.new MessgaeDelete().execute(registrationId);
                } else {

                    Log.i(TAG, "Ignoring unregister callback");
                }

           GCMRegistrar.setRegisteredOnServer(context, false);
         }
         catch (Exception e) {
             e.printStackTrace();
         }
    }

    @Override
    protected void onMessage(Context context, Intent intent) {
        Log.i(TAG, "Received message");
      //  String message = getString(R.string.gcm_message);
        String message = intent.getExtras().getString("message");
        Log.d("Message Received", message);

        generateNotification(context, message);
    }


    }

    @Override
    protected boolean onRecoverableError(Context context, String errorId) {
        // log message
        Log.i(TAG, "Received recoverable error: " + errorId);

        return super.onRecoverableError(context, errorId);
    }

    private static void generateNotification(Context context, String message) {
        int icon = R.drawable.ic_stat_gcm;
        long when = System.currentTimeMillis();
        NotificationManager notificationManager = (NotificationManager)
                context.getSystemService(Context.NOTIFICATION_SERVICE);
        Notification notification = new Notification(icon, message, when);
        String title = context.getString(R.string.app_name);
        Intent notificationIntent = new Intent(context, DemoActivity.class);
        // set intent so it does not start a new activity
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
                Intent.FLAG_ACTIVITY_SINGLE_TOP);
        PendingIntent intent =
                PendingIntent.getActivity(context, 0, notificationIntent, 0);
        notification.setLatestEventInfo(context, title, message, intent);
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        notificationManager.notify(0, notification);
    }

}

Please help me to resolve this problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T13:00:48+00:00Added an answer on June 17, 2026 at 1:00 pm

    You normally don’t call GCMRegistrar.unregister(). You are automatically “unregistered” if you uninstall the application.
    Purpose of this method is in my opinion solely to allow explicit deregistering from within the application. For example if the user has the possibility to turn auto sync completely off there is no need to be registered.
    You can also not be notified about the fact that the app is being uninstalled. The app will never notice since there is no such thing like “preUninstall” or such.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have implemented C2DM (Android Push Notification) to my app and all is working
I have successfully implemented the GCM framework for push notification in my android application.But
I have implemented UrbanAirship Push notification in my app. But I am little bit
I have implemented a sample push notification service for my App. Right now I
I have implemented Facebook into my app but now I find that whenever I
I have implemented Apple Push Notification service using Urban Airship and successfully received the
I have implemented Push Notification and have been using Default sounds every time. I
I have implemented whole push notification service for my application using easyapns . I
I have registered with RIM for the push notification evaluation. But i cant find
Again same question title but requirement is somewhat different. We have implemented push notification

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.