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 8544197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:29:51+00:00 2026-06-11T12:29:51+00:00

My application start Registration id create every time and send to server. public class

  • 0

My application start Registration id create every time and send to server.

public class MariTimeGlobalNewsSplash extends Activity {
    /** Called when the activity is first created. */

    public final static String AUTH = "authentication";
    AsyncTask<Void, Void, Void> mRegisterTask;
    String TAG = "MariTimeGlobalNewsSplash";
    TextView mDisplay;
    @Override    
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.maritimes_global_news_splash);
        mDisplay = (TextView) findViewById(R.id.display);

        Thread threadMenu = new Thread(new Runnable() {
            public void run() {
                try {                   
                    Thread.sleep(2000);
                    HandlerMenu.sendEmptyMessage(0);

                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        threadMenu.start();

        Log.i(TAG,
                "================Inside OnCreate Method==============================");
        checkNotNull(SERVER_URL, "SERVER_URL");
        checkNotNull(SENDER_ID, "SENDER_ID");
        // Make sure the device has the proper dependencies.
        GCMRegistrar.checkDevice(getBaseContext());
        // Make sure the manifest was properly set - comment out this line
        // while developing the app, then uncomment it when it's ready.
        GCMRegistrar.checkManifest(getBaseContext());

        registerReceiver(mHandleMessageReceiver, new IntentFilter(
                DISPLAY_MESSAGE_ACTION));
        final String regId = GCMRegistrar.getRegistrationId(this);
        if (regId.equals("")) {
            Log.i(TAG,
                    "================Inside if in regId=null ==============================");
            // Automatically registers application on startup.
            GCMRegistrar.register(this, SENDER_ID);
        } else {
            Log.i(TAG,
                    "================Inside else in regId=null ==============================");
            // Device is already registered on GCM, needs to check if it is
            // registered on our server as well.
            if (GCMRegistrar.isRegisteredOnServer(this)) {
                // Skips registration.
                Log.i(TAG,  "================Inside else in regId=null Already register on Server =============================");
                mDisplay.append(getString(R.string.already_registered) + "\n");
                Log.i("m Display regId",""+ mDisplay);
            } else {
                Log.i(TAG,
                        "================Inside else in regId=null trying to  register on Server =============================");
                // Try to register again, but not in the UI thread.
                // It's also necessary to cancel the thread onDestroy(),
                // hence the use of AsyncTask instead of a raw thread.
                final Context context = this;
                mRegisterTask = new AsyncTask<Void, Void, Void>() {

                    @Override
                    protected Void doInBackground(Void... params) {
                        Log.i(TAG,
                                "================Inside doInBackground Method==============================");
                        boolean registered = ServerUtilities.register(context,
                                regId);
                        // At this point all attempts to register with the app
                        // server failed, so we need to unregister the device
                        // from GCM - the app will try to register again when
                        // it is restarted. Note that GCM will send an
                        // unregistered callback upon completion, but
                        // GCMIntentService.onUnregistered() will ignore it.
                        if (!registered) {
                            GCMRegistrar.unregister(context);
                        }
                        return null;
                    }

                    @Override
                    protected void onPostExecute(Void result) {
                        Log.i(TAG,
                                "================Inside onPostExecute Method==============================");
                        mRegisterTask = null;
                    }

                };
                mRegisterTask.execute(null, null, null);
            }
        }       

    }

      public void register(View view) {
        Log.i("C2DM", "start registration process");
        Intent intent = new Intent("com.google.android.c2dm.intent.REGISTER");
        intent.putExtra("app", PendingIntent.getBroadcast(this, 0,new Intent(), 0));
        intent.putExtra("sender", "60905422365");        
        startService(intent);
    }

    public void showRegistrationId(View view) {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        String string = prefs.getString(AUTH, "n/a");
        Toast.makeText(this, string, Toast.LENGTH_LONG).show();
        Log.i("C2DM RegId", string);

    }           

    Handler HandlerMenu = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            new Handler().postDelayed(new Runnable(){

                public void run() {

                    Intent i = new Intent(MariTimeGlobalNewsSplash.this,NewsScreenActivity.class);
                    startActivity(i);

                    finish();
                }

            }, 0);

            finish();
        }
    };
    @Override
    protected void onDestroy() {
        Log.i(TAG,
                "================Inside  OnDestroy  Method==============================");
        if (mRegisterTask != null) {
            mRegisterTask.cancel(true);
        }
        unregisterReceiver(mHandleMessageReceiver);
        GCMRegistrar.onDestroy(getBaseContext());
        super.onDestroy();
    }

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

    private final BroadcastReceiver mHandleMessageReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            Log.i(TAG,
                    "================Inside OnReceive in BroadcastReceiver Method==============================");
            String newMessage = intent.getExtras().getString(EXTRA_MESSAGE);
            mDisplay.append(newMessage + "\n");
        }
    };
}
  • 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-11T12:29:52+00:00Added an answer on June 11, 2026 at 12:29 pm
    public class MariTimeGlobalNewsSplash extends Activity {
        /** Called when the activity is first created. */
    
        TextView mDisplay;
        AsyncTask<Void, Void, Void> mRegisterTask;
        String TAG="MariTimeGlobalNews";
        public final static String AUTH = "authentication";
    
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            requestWindowFeature(Window.FEATURE_NO_TITLE);
            setContentView(R.layout.maritimes_global_news_splash);
            Thread threadMenu = new Thread(new Runnable() {
                public void run() {
                    try {                   
                        Thread.sleep(2000);
                        HandlerMenu.sendEmptyMessage(0);
    
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            });
            threadMenu.start();
    
    
             checkNotNull(SERVER_URL, "SERVER_URL");
                checkNotNull(SENDER_ID, "SENDER_ID");
                // Make sure the device has the proper dependencies.
                GCMRegistrar.checkDevice(this);
                // Make sure the manifest was properly set - comment out this line
                // while developing the app, then uncomment it when it's ready.
                GCMRegistrar.checkManifest(this);
           //     setContentView(R.layout.main);
                mDisplay = (TextView) findViewById(R.id.display);
                registerReceiver(mHandleMessageReceiver,
                        new IntentFilter(DISPLAY_MESSAGE_ACTION));
                final String regId = GCMRegistrar.getRegistrationId(this);
                if (regId.equals("")) {
                    Log.i(TAG, "================Inside if in regId=null ==============================");
                    // Automatically registers application on startup.
                    GCMRegistrar.register(this, SENDER_ID);
                } else {
                    Log.i(TAG, "================Inside else in regId=null ==============================");
                    // Device is already registered on GCM, needs to check if it is
                    // registered on our server as well.
                    if (GCMRegistrar.isRegisteredOnServer(this)) {
                        // Skips registration.
                        Log.i(TAG, "================Inside else in regId=null Already register on Server =============================");
                        mDisplay.append(getString(R.string.already_registered) + "\n");
                    } else {
                        Log.i(TAG, "================Inside else in regId=null trying to  register on Server =============================");
                        // Try to register again, but not in the UI thread.
                        // It's also necessary to cancel the thread onDestroy(),
                        // hence the use of AsyncTask instead of a raw thread.
                        final Context context = this;
                        mRegisterTask = new AsyncTask<Void, Void, Void>() {
    
                            @Override
                            protected Void doInBackground(Void... params) {
                                Log.i(TAG, "================Inside doInBackground Method==============================");
                                boolean registered =
                                        ServerUtilities.register(context, regId);
                                // At this point all attempts to register with the app
                                // server failed, so we need to unregister the device
                                // from GCM - the app will try to register again when
                                // it is restarted. Note that GCM will send an
                                // unregistered callback upon completion, but
                                // GCMIntentService.onUnregistered() will ignore it.
                                if (!registered) {
                                    GCMRegistrar.unregister(context);
                                }
                                return null;
                            }
    
                            @Override
                            protected void onPostExecute(Void result) {
                                Log.i(TAG, "================Inside onPostExecute Method==============================");
                                mRegisterTask = null;
                            }
    
                        };
                        mRegisterTask.execute(null, null, null);
                    }
    
                }
    
        }
    
    
          public void register(View view) {
                Log.i("C2DM", "start registration process");
                Intent intent = new Intent("com.google.android.c2dm.intent.REGISTER");
                intent.putExtra("app", PendingIntent.getBroadcast(this, 0,new Intent(), 0));
                intent.putExtra("sender", "123456789101");       
                startService(intent);
            }
    
            public void showRegistrationId(View view) {
                SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
                String string = prefs.getString(AUTH, "n/a");
                Toast.makeText(this, string, Toast.LENGTH_LONG).show();
                Log.i("C2DM RegId", string);
    
            }           
    
    
        Handler HandlerMenu = new Handler() {
            @Override
            public void handleMessage(Message msg) {
    
                Intent i = new Intent(MariTimeGlobalNewsSplash.this,NewsScreenActivity.class);
                startActivity(i);
                finish();
            }
        };
    
          @Override
            protected void onDestroy() {
                Log.i(TAG, "================Inside  OnDestroy  Method==============================");
                if (mRegisterTask != null) {
                    mRegisterTask.cancel(true);
                }
                unregisterReceiver(mHandleMessageReceiver);
                GCMRegistrar.onDestroy(getBaseContext());
                super.onDestroy();
            }
    
            private void checkNotNull(Object reference, String name) {
                Log.i(TAG, "================Inside checkNotNull  Method==============================");
                if (reference == null) {
                    throw new NullPointerException(
                            getString(R.string.error_config, name));
                }
            }
    
            private final BroadcastReceiver mHandleMessageReceiver =
                    new BroadcastReceiver() {
    
                @Override
                public void onReceive(Context context, Intent intent) {
                    Log.i(TAG, "================Inside OnReceive in BroadcastReceiver Method==============================");
                    String newMessage = intent.getExtras().getString(EXTRA_MESSAGE);
                    mDisplay.append(newMessage + "\n");
                }
            };
    
            public static void trimCache(MariTimeGlobalNewsSplash context) {
                try {
                    File dir = context.getCacheDir();
                    if (dir != null && dir.isDirectory()) {
                        deleteDir(dir);
    
                    }
                } catch (Exception e) {
                    // TODO: handle exception
                }
    
            }
    
            public static boolean deleteDir(File dir) {
                if (dir!=null && dir.isDirectory()) {
                    String[] children = dir.list();
                    for (int i = 0; i < children.length; i++) {
                        boolean success = deleteDir(new File(dir, children[i]));
                        if (!success) {
                            return false;
                        }
                    }
                }
    
                // The directory is now empty so delete it
                return dir.delete();
            }
    
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

in my Application I'am currently sending a registration intent to the google server everytime
On application start I'm creating Config object (Singleton). How could I make Config object
My idea is to make an application start automatically when a message from a
I wrote these lines in My Application start event: var mongo = new Mongo();
I want to put some images in an area at the application start. As
How can we have the bluetooth discoverable status on application start I have an
I have in my application many bitmaps. They are loaded when application start. In
I've declared an object which gets instantiated on application start. I want to access
In my Silverlight application, I load all the images I need at application start
I am going to create a new web application that is very customized. It

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.