E N D
Activities • Activity is a window that contains the user interface of your application,typically an application has one or more activites,the main aim of the activity is to interact with the user,From the moment ,the activity appears on the screen to the moment it is hidden,it goes through a number of stages known as a activity life cycle
Activity Manager is responsible for creating, destroying, and overall managing activities. For example, when the user starts an application for the first time, the activity manager will create its activity and put it onto the screen. Later, when the user switches screens, the activity manger will move that previous activity to a holding place. This way, if the user wants to go back to an older activity, it can be started more quickly. Older activities that user hasn’t used in a while will be destroyed in order to free more space for the currently active one. This mechanism is designed to help improve the speed of user interface and thus improve the overall user experience.
Starting state • When an activity doesn’t exist in memory, it is in Starting State. While it’s starting up, the activity will go through a whole set of callback methods that you as a developer have an opportunity to fill out. • Keep in mind that this transition from Starting State to Running State is one of the most expensive operations in terms of computing time needed. The computing time directly effects the battery life of the device as well. This is the exact reason why we don’t automatically destroy activities that are no longer shown. User may want to come back to them, so we keep them around for awhile
Running state • Activity in a Running State is the one that is currently on the screen interacting with the user. We also say this activity is in focus, meaning that all user interactions, such as typing, touching screen, clicking buttons, are handled by this one activity. As such, there is only one running activity at any one time. The running activity is the one that has all the priorities in terms of getting memory and resources needed to run as fast as possible. This is because Android wants to make sure the running activity is zippy and responsive to user.
Paused state • When an activity is not in focus (i.e. not interacting with the user) but still visible on the screen, we say it’s in Paused State. This is not a very typical scenario since the screen is usually small and an activity is either taking the whole screen or not at all. We often see this case with dialog boxes that come up in front an activity causing it to become Paused. Paused State is a state that all activities go through it en route to being stopped.Pausedactivities still have high priority in terms of getting memory and other resources. This is because they are visible and cannot be removed from the screen without making it look very strange to the use
Stopped state • When an activity is not visible, but still in memory, we say it’s in Stopped State. Stopped activity could be brought back to front to become a Running activity again. Or, it could be destroyed and removed from memory.Systemkeeps activities around in Stopped State because it is likely that the user will still want to get back to those activities some time soon. And restarting a stopped activity is far cheaper than starting an activity from scratch. That is because we already have all the objects loaded in memory and just simply have to bring it all up to foregroun Stopped activities can also, an any point, be removed from memory.
Destroyed state • A destroyed activity is no longer in memory. The Activity Manager decided that this activity is no longer needed, and as such has removed it. Before the activity is destroyed, you, the developer, have an opportunity to perform certain actions, such as save any unsaved information. However, there’s no guarantee that your activity will be Stopped prior to being Destroyed. It is possible that a Paused activity gets destroyed as well. For that reason, it is better to do important work, such as saving unsaved data, en route to being Paused rather than Destroyed.
The fact that an activity is in Running State doesn’t mean it’s doing much. It could be just sitting there and waiting for user input. Similarly, an activity in Stopped State is not necessarily doing nothing. The state names mostly refer to how active the activity is with respect to user input. In other words, weather an activity is in visible, in focus, or not visible at all.
intents • An intent is a glue that enables different activities from different applications to work together seamlessly ensuring that tasks can be performed as though they belong to one single application. • Intents are messages that are sent among major building blocks. They trigger an activity to start up, a service to start or stop, or are simply broadcasts.
Understanding the activity To create an cativity you create a java class that extends the activity base class,your activity class loads its UI comonents using the XML file defined in the res/layout folder; setContentView(R.layout.main)
Your each and every activity would be define into your AndroidManifest.xml file
Activity(continued) Activity base class defines a series of events that governs the lifecycle of an Activity, the activity class defines the following events. • onCreate() — Called when the activity is first created • onStart() — Called when the activity becomes visible to the user • onResume() — Called when the activity starts interacting with the user • onPause() — Called when the current activity is being paused and the previous activity is being resumed • onStop() — Called when the activity is no longer visible to the user • onDestroy() — Called before the activity is destroyed by the system (either manually or by the system to conserve memory) • onRestart() — Called when the activity has been stopped and is restarting again
First I will show you Logcat, this is a nice and quick way to exchange information from the application on your device and the development computer. • To use Logcat first import android.util.Log in your project. Now you can call the static class Log from your project to start logging. As you can see below, Logcat has different levels of logging. When debugging we’ll just use Debug (D) to log the progress. Of course when you want to log an actual error you will use Error (E). • V — Verbose (lowest priority) • D — Debug • I — Info • W — Warning • E — Error • F — Fatal • S — Silent (highest priority, on which nothing is ever printed)
To Display the activity as a Dialog • By default an activity occupys the entire screen ,we can apply a dialog theme to an activity sothat so that it is displayed as a floating dialog,eg you can customize your activity to display as a popup,warning the user about the action the user is going to perform To apply a dialog theme to an activity, simply modify the <Activity> element in the AndroidManifest.xml file by adding the android:theme attribute:
Charsequency[] • String implements the CharSequenceinterface. CharSequence is implemented by String, but also CharBuffer, Segment, StringBuffer, StringBuilder. • So a String[] and a CharSequence[] is essentially the same. But CharSequence is the abstraction, and String is the implementation. • By the way, '[]' denotes an array of objects. So String[] is an array of strings. And String itself is an array of characters