1. Download our Official Android App: Forums for Android!

Apps Some basics doubts in Android Programming

Discussion in 'Android Development' started by Vinoth Vino, Mar 24, 2016.

  1. Vinoth Vino

    Vinoth Vino Lurker
    Thread Starter
    Rank:
    None
    Points:
    6
    Posts:
    4
    Joined:
    Mar 24, 2016

    Mar 24, 2016
    4
    1
    6
    Male
    Helo guys, I've simple doubts in android.Please make me understand. I can't go without knowing this clearly.

    1.Why super keyword ?

    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    addListenerOnButton();

    }


    Why we're using super.onCreate method in onCreate.. What it'll do ? I don't know the flow of execution too...(As per my knowledge.. First onCreate method will executed with Bundle(Bundle stores the user states) thn it moves to setContentView without executing super.onCreate.... If we've come to home and then when we open the app..then "super.onCreate" will execute with old state... isn't it ?

    2.Why we're inheriting some classes ?
    As per my knowledge... By way of inheriting we've the properties of parent class(for ex: Activity) so that only we're inheriting the parent class.. isn't it ?

    3.Why should I wanna extend Activity ?
    As per my knowledge.. If we wanna use activity then we've to extend Activity and override activity lifecycles as per our wish... isn't it ?

    4.Why should I wanna extend SQLiteOpenHelper class ?
    If we wanna create database then we wanna extend SQLiteOpenHelper class but I studied that SQLiteDatabase method called openOrCreate or similar methods are only used to create databases ? Then why should i wanna extend SQLiteOpenHelper class ????? (As per my knowledge... It's the main thing in sql database..In this "SQLiteOpenHelper" class only contains the sqlite database onCreate lifecycle methods etc.... so we wanna extend this class and then use openOrCreate or similar methods to achieve database creation in onCreate lifecycle... isn't it ?)

    5.What is context ? Why we're passing context as parameter in super keyword ?(ex: onCreate lifecycle method)
    Context is used to access system related informations ?

    6.What's the use of using getters and setters in android ?

    package com.example.sqlite;
    public class Contact {
    int _id;
    String _name;
    String _phone_number;
    public Contact(){ }
    public Contact(int id, String name, String _phone_number){
    this._id = id;
    this._name = name;
    this._phone_number = _phone_number;
    }

    public Contact(String name, String _phone_number){
    this._name = name;
    this._phone_number = _phone_number;
    }
    public int getID(){
    return this._id;
    }
    public void setID(int id){
    this._id = id;
    }
    public String getName(){
    return this._name;
    }
    public void setName(String name){
    this._name = name;
    }
    public String getPhoneNumber(){
    return this._phone_number;
    }

    public void setPhoneNumber(String phone_number){
    this._phone_number = phone_number;
    }
    }


    7.What's the use of passing context in parameter ? and why we're passing DatabaseName,Database version ? In which time this super method executed ? then who will receive this as arguments ?


    public DatabaseHandler(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
    //3rd argument to be passed is CursorFactory instance
    }

    Source : javatpoint

    8.Here,How I achieved "db.execSQL" ? I'm just passing SQLite as argument only know ? Then how can i use db.execSQL in this onCreeate method ? and my doubt is I'm passing onCreate(SQLiteDatabase db) as argument...then who'll receive this argument ????????

    public void onCreate(SQLiteDatabase db) {
    String CREATE_CONTACTS_TABLE = "CREATE TABLE " + TABLE_CONTACTS + "("
    + KEY_ID + " INTEGER PRIMARY KEY," + KEY_NAME + " TEXT,"
    + KEY_PH_NO + " TEXT" + ")";
    db.execSQL(CREATE_CONTACTS_TABLE);
    }



    These are my basic doubts.. I can't go to anyother topic without knowing these things... I think i didn't learn all basics clearly..Please help me out..... ;'( ;'( Thank you so much in advanced :)
     

    Advertisement

  2. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #11
    Points:
    1,988
    Posts:
    7,887
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    7,887
    11,548
    1,988
    Male
    Software developer
    South West of England
    Stop immediately, and get a book on Java programming. Forget about writing Android apps at the moment. You need to educate yourself about the basics of the Java language. Asking a question like this shows that you don't understand class inheritance, which is a basic concept you need to grasp.

    Attempting to do anything more complex at this stage will be futile, you have too many basic gaps in your knowledge.

    After you read and understand the Java programming book, buy a beginners book on writing Android apps.

    I could answer your questions, but it would probably lead to more questions, and as they say, you have to learn to walk before you can run.
     
    Strazil, GodLovesYou and Vinoth Vino like this.
  3. Vinoth Vino

    Vinoth Vino Lurker
    Thread Starter
    Rank:
    None
    Points:
    6
    Posts:
    4
    Joined:
    Mar 24, 2016

    Mar 24, 2016
    4
    1
    6
    Male
    Okay..... I learned java inheritance and all stuffs.... But didn't learn well and When I came to android I forgot all in java. I'm also thinking to learn java from beginning... Thanks :)
     
    LV426 likes this.
  4. wishutdev

    wishutdev Lurker
    Rank:
    None
    Points:
    15
    Posts:
    1
    Joined:
    Mar 24, 2016

    Mar 24, 2016
    1
    0
    15
    Male
    Dev wanabe. Also retired.
    Chicago
    I have worked my way through books and find they can be difficult. One resource I liked is udemy.com. I bought my courses on sale, but the standard price is less now. The best course for me was Java Tutorial for Complete Beginners by John Purcell. He is a very good instructor. Also, Learn Android 4.0 Programming in Java by John Purcell was very helpful.

    The Complete Android & Java Developer: Build 21 Android-Apps by Fahd Sheraz is good too and he uses Android Studio.

    Note: I am not connected to Udemy or Purcell, this is just what worked well for me.
     

Share This Page

Loading...