Android Developer Activity
Android Activity
Android activity lifecycle
An activity is a single screen
in android. It is like a window or frame of Java. By the help of activity, you can place all your UI components or widgets in a
single screen. The 7 lifecycle method
of Activity describes
how activity will
behave at different states. Android Training good career in further
It provides details about the invocation of
life cycle methods of activity. In this example, we are displaying the content
on the logcat.
File: MainActivity.java
1.
package example.javatpoint.com.activitylifecycle;
2.
3.
import android.app.Activity;
4.
import android.os.Bundle;
5.
import android.util.Log;
6.
7.
public class MainActivity extends Activity {
8.
9.
@Override
10. protected void onCreate(Bundle savedInstanceState) {
11. super.onCreate(savedInstanceState);
12. setContentView(R.layout.activity_main);
13. Log.d("lifecycle","onCreate invoked");
14. }
15. @Override
16. protected void onStart() {
17. super.onStart();
18. Log.d("lifecycle","onStart invoked");
19. }
20. @Override
21. protected void onResume() {
22. super.onResume();
23. Log.d("lifecycle","onResume invoked");
24. }
25. @Override
26. protected void onPause() {
27. super.onPause();
28. Log.d("lifecycle","onPause invoked");
29. }
30. @Override
31. protected void onStop() {
32. super.onStop();
33. Log.d("lifecycle","onStop invoked");
34. }
35. @Override
36. protected void onRestart() {
37. super.onRestart();
38. Log.d("lifecycle","onRestart invoked");
39. }
40. @Override
41. protected void onDestroy() {
42. super.onDestroy();
43. Log.d("lifecycle","onDestroy invoked");
44. }
45. }
Output:
You will not see any output on the emulator or
device. You need to open logcat.
Sr.No
|
Callback & Description
|
1
|
onCreate()
This is
the first callback and called when the activity is first created.
|
2
|
onStart()
This
callback is called when the activity becomes visible to the user.
|
3
|
onResume()
This is
called when the user starts interacting with the application.
|
4
|
onPause()
The
paused activity does not receive user input and cannot execute any code and
called when the current activity is being paused and the previous activity is
being resumed.
|
5
|
onStop()
This
callback is called when the activity is no longer visible.
|
6
|
onDestroy()
This
callback is called before the activity is destroyed by the system.
|
7
|
onRestart()
This
callback is called when the activity restarts after stopping it.
|
Conclusion
Android Career
Android class works in the same way. By extending
the Activity class which haveonCreate(Bundle
bundle) method in which meaningful code is written and to execute that code in
the defined activity, use the super keyword
with the method onCreate()like super.onCreate(bundle)
By 2024, there will be 48,500 additional tech jobs. ... Become an Android Developerif you're keen on a flexible and stimulating career, which is in high demand. HyperionDev offers a 6-month, part-time Mobile Developer Bootcamp aligned to the Google Associate Android Developer certification.
Comments
Post a Comment