Java Reference
In-Depth Information
The following example shows you how to start SimpleActivity2 implicitly:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW); // Use Intent con-
stants instead of literal ...
intent.setType("image/jpeg");
intent.addCategory(Intent.CATEGORY_DEFAULT);
//
...
strings to reduce errors.
SimpleActivity.this.startActivity(intent);
The first four lines create an Intent object describing an implicit intent. Values
passed to Intent 's Intent setAction(String action) , Intent
setType(String type) ,and Intent addCategory(String category)
methodsspecifytheintent'saction,MIMEtype,andcategory.TheyhelpAndroididenti-
fy SimpleActivity2 as the activity to be started.
ACTIVITIES, TASKS, AND THE ACTIVITY STACK
Android refers to a sequence of related activities as a task and provides an activity
stack (also known as history stack or back stack ) to remember this sequence. The
activitystartingthetaskistheinitialactivitypushedontothestackandisknownas
the root activity . This activity is typically the activity selected by the user via the
device'sapplauncher.Theactivitythat'scurrentlyrunningislocatedatthetopofthe
stack.
When the current activity starts another, the new activity is pushed onto the stack
andtakesfocus(becomestherunningactivity).Thepreviousactivityremainsonthe
stack, but is stopped. When an activity stops, the system retains the current state of
its user interface.
Whentheuserpressesthedevice'sBACKkey,thecurrentactivityispoppedfromthe
stack (the activity is destroyed), and the previous activity resumes operation as the
running activity (the previous state of its user interface is restored).
Activitiesinthestackareneverrearranged,onlypushedandpoppedfromthestack.
Activitiesarepushedontothestackwhenstartedbythecurrentactivity,andpopped
off the stack when the user leaves them via the BACK key.
Each time the user presses BACK, an activity is popped off the stack to reveal
the previous activity. This continues until the user returns to the home screen or to
whicheveractivitywasrunningwhenthetaskbegan.Whenallactivitiesareremoved
from the stack, the task no longer exists.
Search WWH ::




Custom Search