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

  • Home
  • SEARCH
  • 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 8279143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:14:12+00:00 2026-06-08T09:14:12+00:00

public class FBPost extends Service{ private Bundle params = new Bundle(); private String userID=;

  • 0
public class FBPost extends Service{

        private Bundle params = new Bundle();
        private String userID="";

        String response;

        public void onCreate(String userID,String name)
        {
            super.onCreate();
            params.putString("message", "Test " + new Date().toLocaleString() );
            params.putString("caption", "Hey there");
            this.userID=userID;
        }


        @Override
        public int onStartCommand( Intent intent , int flags , int startId )
        {
            if(checkInternetConnection())
            {
                fb_post();
            return 0;
            }
            else
            {
                 BroadcastReceiver connec_recv= new BroadcastReceiver() {

                     @Override
                     public void onReceive(Context context, Intent intent) {

                         if(checkInternetConnection())
                             fb_post();
                         } 
                 };

                 final IntentFilter intentFilter = new IntentFilter();
                 intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
                 registerReceiver(connec_recv, intentFilter);
            }
        }

        @Override
        public IBinder onBind(Intent arg0) {
            // TODO Auto-generated method stub
            return null;
        }

         private boolean checkInternetConnection() {
                ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

                // test for connection
                if (cm.getActiveNetworkInfo() != null
                        && cm.getActiveNetworkInfo().isAvailable()
                        && cm.getActiveNetworkInfo().isConnected()) {
                     try{
                            URL url = new URL("http://www.google.com");
                            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
                            in.close();
                            return true;
                        } catch (Exception e) {
                            return false;
                        }
                }
                    return false;
            }

         private void fb_post()
         {
            //MORE CODE
         }


}

what if there’s still no internet conectivity? Should i just call another instance of the same service from the broadcast receiver instead of fb_post()? Can I make a service wait() and then notify() every time a connectivity broadcast receiver recieves a connection change broadcast?

  • 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-08T09:14:14+00:00Added an answer on June 8, 2026 at 9:14 am

    In my opinion the right way to implement this kind of functionality is as follows:

    • If there is no connection – give up the Service, register a BroadcastReceiver to listen for connection changes and save a flag somewhere (SharedPreferences for example) telling that there is work left to do
    • When the connection is established and your flag is true – start the Service again and do the job

    Hope this helps.

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

Sidebar

Related Questions

public class SettingsActivity extends PreferenceActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /*
public class Browser1Activity extends Activity { TextView url; WebView ourBrow; @Override protected void onCreate(Bundle
public class IdAsync extends AsyncTask<String, Void, Void> { AlertDialog alertDialog = new AlertDialog.Builder(MainClass.this).create(); protected
public class Test{ public void Test(String name){}; public static void main() { Test t=new
public class Offer_Popup extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.offer_popup); //newly
public class Test { public static void main(String[] args) { DemoAbstractClass abstractClass = new
public class InterruptedInput { public static void main(String[] args) { InputThread th=new InputThread(); //worker
public class BobDatabase extends SQLiteOpenHelper{ private static final String DATABASE_NAME = bob.db; private static
public class saveButtonListener implements ActionListener{ public void actionPerformed(ActionEvent ev){ JFileChooser chooser= new JFileChooser(); String
public class Boards : TabActivity { protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.Tab);

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.