31 Jul 2017

Make android java code

Let's make Main.Java

This Main class file of  android Java must be an extension of Activity class. It's instantiated by Android system when app is run by user.

public class Main extends Activity
{
 protected void onCreate ()
  {
  }
}
Above is a skeleton which says
Let's have a publicly available code resembling inbuilt code of Activity and let's only change a portion of it called onCreate.
    This function is called when an object of this code is instantiated in RAM memory of Android mobile. What is created is an empty screen shown to user with a top title as Activity label defined in manifest.

We can place many more text and buttons etc in this empty screen by putting code in this custom function.

But what code. So see below.
TextView tv = new TextView (this)

Above statement allocates a textview object in RAM memory.

tv.setText("Hi dude");
This puts Hi dude in its data variable for containing text.

setContentView(tv);
This above statement let's the empty screen window object point to the newly allocated tv object so that contents of tv view object are displayed on mobile screen.

No comments:

Post a Comment