২৬. SearchArabic
২৭. SearchSelection
২৮. SearchSuggestion_Arabic
২৯. SearchTafsir
৩০. SearchVumika
৩১. Settings2
৩২. SimpleIME (কীবোর্ড)
৩৩. SuggestionSelection
৩৪. TokenActivity (মেইন এ্যাক্টিভিটি)
৩৫. TokenExplShow ( ব্যাখ্যা দেখার এ্যাক্টিভিটি)
৩৬. VumikaAndProsongo
৩৭. VumikaAndProsongoText
৩৮. WebViewActivity (মানচিত্র)
৩৯. WebViewShow (মানচিত্র)
৪০. ZekhanePorchilen (যেখানে পড়ছিলেন)
Theory : 2 : OnCreate, OnStart, OnResume, OnPause, OnStop, OnDestroy, OnRestart - Please Explain The Activity LifeCycle
Why can't it be the onResume() is invoked after onRestart() and onCreate() methods just excluding onStart()? What is its purpose?
OK, as my first answer was pretty long I won't extend it further so let's try this...
public DriveToWorkActivity extends Activity
implements onReachedGroceryStoreListener {
}
public GroceryStoreActivity extends Activity {}
PLEASE NOTE: I've deliberately left out the calls to things like
super.onCreate(...)
etc. This is pseudo-code so give me some artistic licence here. ;)
The methods for
DriveToWorkActivity
follow...protected void onCreate(...) {
openGarageDoor();
unlockCarAndGetIn();
closeCarDoorAndPutOnSeatBelt();
putKeyInIgnition();
}
protected void onStart() {
startEngine();
changeRadioStation();
switchOnLightsIfNeeded();
switchOnWipersIfNeeded();
}
protected void onResume() {
applyFootbrake();
releaseHandbrake();
putCarInGear();
drive();
}
protected void onPause() {
putCarInNeutral();
applyHandbrake();
}
protected void onStop() {
switchEveryThingOff();
turnOffEngine();
removeSeatBeltAndGetOutOfCar();
lockCar();
}
protected void onDestroy() {
enterOfficeBuilding();
}
protected void onReachedGroceryStore(...) {
Intent i = new Intent(ACTION_GET_GROCERIES, ..., this, GroceryStoreActivity.class);
}
protected void onRestart() {
unlockCarAndGetIn();
closeDoorAndPutOnSeatBelt();
putKeyInIgnition();
}
OK, so it's another long one (sorry folks). But here's my explanation...
onResume()
is when I start driving and onPause()
is when I come to a temporary stop. So I drive then reach a red light so I pause...the light goes green and I resume. Another red light and I pause, then green so I resume. The onPause() -> onResume() -> onPause() -> onResume()
loop is a tight one and occurs many times through my journey.
The loop from being stopped back through a restart (preparing to carry on my journey) to starting again is perhaps less common. In one case, I spot the Grocery Store and the
GroceryStoreActivity
is started (forcing my DriveToWorkActivity
to the point of onStop()
). When I return from the store, I go through onRestart()
and onStart()
then resume my journey.
I could put the code that's in
onStart()
into both onCreate()
and onRestart()
and not bother to override onStart()
at all but the more that needs to be done between onCreate() -> onResume()
and onRestart() -> onResume()
, the more I'm duplicating things.
So, to requote once more...
Why can't it be the onResume() is invoked after onRestart() and onCreate() methods just excluding onStart()?
If you don't override
onStart()
then this is effectively what happens. Although the onStart()
method of Activity
will be called implicitly, the effect in your code is effectively onCreate() -> onResume()
or onRestart() -> onResume()
.
=======================
onStart()
means Activity
entered into visible state and layout is created but can't interact with this activity layout.Resume()
means now you can do interaction with activity layoutTheory : 1 : What is "Context" in Android ?
Every boss has an assistant to look after, to do all less important and time-consuming tasks. If a file or a cup of coffee is needed, an assistant is on the run. Some bosses barely know what’s going on in the office, so they ask their assistants regarding this too. They do some work themselves but for most other things they need the help of their assistants.
In this scenario,
Boss – is the Android application
Assistant – is context
Files/Cup of coffee – are resources
We generally call context when we need to get information about different parts of our application like Activities, Applications etc.
Some operations(things where the assistant is needed) where context is involved:
- Loading common resources
- Creating dynamic views
- Displaying Toast messages
- Launching Activities etc.
Different ways of getting context:
getContext()
getBaseContext()
getApplicationContext()
this
A Context is a handle to the system; it provides services like resolving resources, obtaining access to databases and preferences, and so on. An Android app has activities. Context is like a handle to the environment your application is currently running in. The activity object inherits the Context object.
What's
Context
exactly?Per the Android reference documentation, it's an entity that represents various environment data. It provides access to local files, databases, class loaders associated to the environment, services (including system-level services), and more. Throughout this book, and in your day-to-day coding with Android, you'll see the Context passed around frequently.
From the "Android in Practice" book, p. 60.
Several Android APIs require a
Context
as parameter
If you look through the various Android APIs, you’ll notice that many of them take an
android.content.Context
object as a parameter. You’ll also see that an Activity or a Service is usually used as a Context
. This works because both of these classes extend from Context
.
An Android Context is an Interface (in the general sense, not in the Java sense; in Java,
Context
is actually an abstract class!) that allows access to application specific resources and class and information about application environment.
If your android app was a web app, your context would be something similar to
ServletContext
(I am not making an exact comparison here).
Your activities and services also extend
Context
, so they inherit all those methods to access the environment information in which the app is running.Definition of Context
- Context represents environment data
- It provides access to things such as databases
Simpler terms (example 1)
- Consider Person-X is the CEO of a start-up software company.
- There is a lead architect present in the company, this lead architect does all the work in the company which involves such as database, UI etc.
- Now the CEO Hires a new Developer.
- It is the Architect who tells the responsibility of the newly hired person based on the skills of the new person that whether he will work on Database or UI etc.
Simpler terms (example 2)
- It's like access of android activity to the app's resource.
- It's similar to when you visit a hotel, you want breakfast, lunch & dinner in the suitable timings, right?
- There are many other things you like during the time of stay. How do you get these things?
- You ask the room-service person to bring these things for you.
- Here the room-service person is the context considering you are the single activity and the hotel to be your app, finally the breakfast, lunch & dinner have to be the resources.
Things that involve context are:
- Loading a resource.
- Launching a new activity.
- Creating views.
- obtaining system service.
Context is the base class for Activity, Service, Application, etc
Another way to describe this: Consider context as remote of a TV & channel's in the television are resources, services, using intents etc - - - Here remote acts as an access to get access to all the different resources into foreground.
- So, Remote has access to channels such as resources, services, using intents etc ....
- Likewise ... Whoever has access to remote naturally has access to all the things such as resources, services, using intents etc
Different methods by which you can get context
getApplicationContext()
getContext()
getBaseContext()
- or
this
(when in the activity class)
Example:
TextView TV=new TextView(this);
this
-> refers to the context of the current activity.
Subscribe to:
Posts (Atom)
Featured Post
Lesson 1 : Android Studio : DownLoad And Install and First App
বিসমিল্লাহির রাহমানির রাহীম Lesson 1 : Android Studio : DownLoad And Install and First App এই লেসনটির ভিডিও ইউটিউবে দেখতে এখানে ক্ল...
Popular Posts
-
Errors are : (Maybe both In Android or AndroidX) 1. Android X: tools:replace specified at line: for attribute, but no new value speci...
-
বিসমিল্লাহির রাহমানির রাহীম Lesson 1 : Android Studio : DownLoad And Install and First App এই লেসনটির ভিডিও ইউটিউবে দেখতে এখানে ক্ল...
-
Google Spread Sheets As Android Web Database এই প্রজেক্টে দুটি পার্ট থাকবে, ১। এ্যান্ড্রয়েড পার্ট ২। ওয়েব পার্ট ===...
-
আমরা প্রথমে একটি Launcer Activity তৈরী করব, এরপর এই এ্যাক্টিভিটি থেকে বিভিন্ন এ্যাক্টিভিটিতে বাটন ক্লিক এর মাধ্যমে যাবো। এবং সেই এ্যাক্টিভ...
-
আলহামদুলিল্লাহ, ছুম্মা আলহামদুলিল্লাহ। আল্লাহুম্মা সল্লি আলা মুহাম্মাদিন আবদিকা ও রাসুলিকা। আমরা তাফহীমুল কুরআন এ্যাাপের মেকিং এ্যাপ তৈর...
-
In this Video We are Showing Android Book App Making , Two Method : List view and Button Click . 1. First Method: List View From Array....
-
java part : package first.learn.myapplication ; import androidx.appcompat.app.AppCompatActivity ; import android.os.Bundle ; import android...
-
আপনি যদি রেজিষ্ট্রেশন ফী এবং কোর্স ফী পরিশোধ করে থাকেন তবে ডাউনলোড করার জন্য এখানে ইনবক্স করুন : Inbox
-
বিসমিল্লাহির রাহমানির রাহীম Android Learning :Beginners To Paid Professional লেসন 5 এর আলোচ্য বিষয় : ১। একটি নতুন এ্যাক্ট...
-
2. Java Development kit (JDK) ডাউনলোড করুন । ডাউনলোড । আপনার পিসির কনফিগারেশন অনুযায়ী ডাউনলোড করে ইনষ্টল করে নিন। আপনার পিসির কনফিগার...