Android is quite complex, and a lot of things are happening in the background. This includes environment setup, event handling (looping and waiting on a queue), and everything else that makes Android be Android. So, when you create your project, you are
adding to the process, rather than creating it.
vinoth vino wrote:
1.Why super keyword ?
OnCreate() creates the environment. Android does a lot of things for you. By overriding onCreate, you can
also have things done then, but you still need to let Android do its own thing. super.onCreate() runs all the stock Android code first.
2.Why we're inheriting some classes ?
Because there's a lot of code being done for you. Inheriting brings it all into context and runs things in the background.
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 ?
Technically, if you implemented everything in Activity (and that would be a lot of code) you would be able to extend Object yourself. But, for ease of use, and automatically using whatever Android fixes itself in later versions, use AppCompatActivity and let Google manage that headache for you.
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 ?)
Helpers tend to be conveniences, and other coders might be used to it (and expect it!) in other projects. Plus, (maybe!) sometimes the code helper helps better when you use standard classes. Your choice really.
5.What is context ? Why we're passing context as parameter in super keyword ?(ex: onCreate lifecycle method)
Context is an easy but advanced topic. For now, imagine it is a reference to the current activity, and has to be passed on object creation so when the Android code creates the object, it has a reference to your activity so it can list it as the object's parent. A callback creates a new context (because, by definition, the other code "is in control" and that isn't you). Passing context to a callback method let's the called method know who the real parent was.
For the most part, you can ignore what Context is until you have greater familiarity with Android.
6.What's the use of using getters and setters in android ?
It's just a standard to keep a variable private and allow specific code to be executed when setting or retrieving a variable. It's done this way in many languages, and some even write the code for you. Apple's XCode has a command to write them, Android Studio will offer to do it if you hit alt-enter, and so on. Not allowing direct access to variables can be very important, especially if code must be run to set it. Basically, if you have to mark the variable private, and you want it to be set and/or read, you'll want getters and setters.
The nomenclature is a standard or sorts. Personally, i hate it, and in my own code i just overload the variable name.
I think that's much cleaner, but it isn't the standard, and is probably frowned upon. In any case, getters and setters are goods practice. If you feel a variable should not be directly accessed, make it private and add getters and setters. You'll likely be thankful much later in the project.
7.What's the use of passing context in parameter ?
It sets the parent for the object. This is a more advanced topic you might want to revisit at a later time.
why we're passing DatabaseName,Database version ?
So when updating the app, Android knows whether to install a new database, upgrade the old one, or leave it be. It's just a standard, and you still have to implement the code yourself.
In which time this super method executed ?
???
then who will receive this as arguments ?
Android's method, which checks the old version to see if it needs updating.
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 ???
Although this seems to be the standard, this is a horrible, terrible, insecure method of running SQL. It is dynamic SQL and should be avoided at nearly all costs. It's so bad i want to cry. I'm to much of a SQL snob to answer this question, sorry.
