- Forum posts: 7
Mar 24, 2016, 5:29:00 AM via Website
Mar 24, 2016 5:29:00 AM via Website
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 ?
p
ublic 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 ????????
p
ublic 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
Recommended editorial content
With your consent, external content is loaded here.
By clicking on the button above, you agree that external content may be displayed to you. Personal data may be transmitted to third-party providers in the process. You can find more information about this in our Privacy Policy.