-3

I am asking this because after reading that , android depend upon components thats why they have removed main() method from, but can we not create a program by adding main() at one place than when ever we need internet.

Than we can place another Internet's main() method and pausing previous main method ?

j0k
  • 22,600
  • 28
  • 79
  • 90
  • This is a very hard to understand question, maybe you'd like to rephrase it and give more information, such as what language you are working with? – Arne Mertz Feb 28 '13 at 11:28
  • Refer this answer: http://stackoverflow.com/a/9293488/2024761 – Rahul Dec 10 '15 at 06:22

2 Answers2

1

At AndroidManifest.xml you need a LAUNCHER activity, and 2 more for network and no network like:

    <activity
        android:name="your.package.StartActivity" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity
        android:name="your.package.NetworkActivity" >
    </activity>

    <activity
        android:name="your.package.NoNetworkActivity" >
    </activity>

At StartActivity.java check connectivity and then choose what activity to start:

 public class StartActivity extends Activity {
     //...


     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);

         // here do the job!!!
         boolean iAmConnected = checkNetwork(); // you need to implement that
         if(iAmConnected) {
           // start network activity
           Intent intent = new Intent(this, NetworkActivity.class);
           startActivity(intent);

         } else  {
           // start no network activity
           Intent intent = new Intent(this, NoNetworkActivity.class);
           startActivity(intent);
         }

     }

    //...
 }

StartActivity can have a setContentView(R.layout.a_splash_screen); or no content view.

madlymad
  • 6,367
  • 6
  • 37
  • 68
0

main() method is only entry point for many languages , same like java android expects some entry point to start the Application (first screen) , in android we will specify which activity has to be started in android manifest file using Intent Filter

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter> 

when the activity started (First Screen is visible to User) it will call the onCreate(Bundle b) method ...activity life cycle methods