Yeah, we have successfully set up the android environment. So what’s next?
I think we can follow the same formalities even though it’s useless.
Okay we can tell Hello to this World through android now.
- Open your eclipse and create a new Android project
- Give your own project name, application name, package name and activity name
- Choose the android platform and SDK version (preferably the latest versions)
- Once you are done click finish
- Now the android project would be created with auto generated class
Find the generated activity class. It should be like this by extending android.app.Activity
package com.example.helloandroid;
import android.app.Activity;
import android.os.Bundle;
public class HelloAndroid extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
From Reference,
- Activity is a single application entity that is used to perform actions.
- Application may have many separate activities
- But the user interacts with them one at a time
- The onCreate() method will be called by the Android system when your Activity starts
- In onCreate() we can perform all initialization and UI setup.
Since the title is about Hello World, Im changing the onCreate() method as below
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
tv.setText("Hello, World");
setContentView(tv);
}
That’s it. Now run the project by Run as “Android Application” and wait to see your
Hello World. By the way we have accomplished our mission.
0 comments:
Post a Comment