javadoc翻訳 〜Activity編〜(3)

The entire lifecycle of an activity is defined by the following Activity methods.
All of these are hooks that you can override to do appropriate work when the
activity changes state. All activities will implement onCreate(Bundle) to do
their initial setup; many will also implement onPause() to commit changes to
data and otherwise prepare to stop interacting with the user. You should always
call up to your superclass when implementing these methods.


	public class Activity extends ApplicationContext {
	     protected void onCreate(Bundle savedInstanceState);

	     protected void onStart();
	     protected void onRestart();

	     protected void onResume();

	     protected void onPause();

	     protected void onStop();

	     protected void onDestroy();

In general the movement through an activity's lifecycle looks like this:
Method Description Killable? Next
onCreate() Called when the activity is first created. This is where you should do all of your normal static set up: create views, bind data to lists, etc. This method also provides you with a Bundle containing the activity's previously frozen state, if there was one. Always followed by onStart(). No onStart()
onRestart() Called after your activity has been stopped, prior to it being started again. Always followed by onStart() No onStart()
onStart() Called when the activity is becoming visible to the user. Followed by onResume() if the activity comes to the foreground, or onStop() if it becomes hidden. No onResume() or onStop()
onResume() Called when the activity will start interacting with the user. At this point your activity is at the top of the activity stack, with user input going to it. Always followed by onPause(). No onPause()
onPause() Called when the system is about to start resuming a previous activity. This is typically used to commit unsaved changes to persistent data, stop animations and other things that may be consuming CPU, etc. Implementations of this method must be very quick because the next activity will not be resumed until this method returns. Followed by either onResume() if the activity returns back to the front, or onStop() if it becomes invisible to the user. Pre-HONEYCOMB onResume() or onStop()
onStop() Called when the activity is no longer visible to the user, because another activity has been resumed and is covering this one. This may happen either because a new activity is being started, an existing one is being brought in front of this one, or this one is being destroyed. Followed by either onRestart() if this activity is coming back to interact with the user, or onDestroy() if this activity is going away. Yes onRestart() or onDestroy()
onDestroy() The final call you receive before your activity is destroyed. This can happen either because the activity is finishing (someone called finish() on it, or because the system is temporarily destroying this instance of the activity to save space. You can distinguish between these two scenarios with the isFinishing() method. Yes Nothing

Method Description Killable? Next
onCreate() Activtyが最初に作成された場合にコールされる。ここで、全ての静的なセットアップを行うべきである。Viewの作成、リストへのデータバインド、等々。このメソッドはまた、Bundleに対して"フリーズ"されて保存されているActivityの以前の状態が存在しているのならば、それを提供する。常にonStart()が続く。 No onStart()
onRestart() Activtyがストップされた後、再び起動される前にコールされる。常にonStart()が続く。 No onStart()
onStart() Activityがユーザから視認可能になった時にコールされる。もしActivityがフォアグラウンドに配置された場合、続いてonResume()がコールされる。また、ユーザから視認不可になったときにはonStop()がコールされる。 No onResume() or onStop()
onResume() Activityがユーザとインタラクトし始めた際にコールされる。このポイントにおいて、Activtyはスタックのトップに位置している。常にonPause()が続く。 No onPause()
onPause() システムが以前に存在したActivtyを再開させようとした際に、(現在のスタックトップActivtyに対して)コールされる。これは主に保存されていない永続的データのコミットや、CPUを消費するアニメーションの停止などを行うために使用される。このメソッドの実装は非常に軽快なものでなくてはならない。なぜなら、次のActivtyはこのメソッドがリターンするまで再開されないからである。もしこのActivtyがフロントへ戻ってきた場合、onResme()がコールされ、また、ユーザから視認不可になったらonStop()がコールされる。 Pre-HONEYCOMB onResume() or onStop()
onStop() Activtyがユーザから視認不可になった時、つまり他のActivtyが再開され、このActivtyを覆っている状態になった時にコールされる。このメソッドコールは新規Axctivityが開始されるか、既存のActivtyがこのActivtyの前面に現れた場合、あるいはこのActivtyが破棄される場合に発生しうる。後にこのActivityがユーザとインタラクトするために再開された場合にはonRestart()がコールされ、またはこのActiytyが破棄されていなくなる場合にはonDestory()がコールされる。 Yes onRestart() or onDestroy()
onDestroy() Activityが破棄される直前、最終的にコールされる。このメソッドコールは誰かがfinish()をコールしたか、システムがスペースを確保するために、このActivtyインスタンスを一時的に破棄した場合、つまりActivtyの終了時に起こりうる。この二つのシナリオはisFinishing()よって判別できる。 Yes Nothing

Note the "Killable" column in the above table -- for those methods that are marked as being killable,
after that method returns the process hosting the activity may killed by the system at any time without
another line of its code being executed. Because of this, you should use the onPause() method to write
any persistent data (such as user edits) to storage. In addition, the method onSaveInstanceState(Bundle)
is called before placing the activity in such a background state, allowing you to save away any dynamic
instance state in your activity into the given Bundle, to be later received in onCreate(Bundle)
if the activity needs to be re-created. See the Process Lifecycle section for more information on
how the lifecycle of a process is tied to the activities it is hosting. Note that it is important
to save persistent data in onPause() instead of onSaveInstanceState(Bundle) because the latter is not
part of the lifecycle callbacks, so will not be called in every situation as described in its documentation.


Be aware that these semantics will change slightly between applications targeting platforms starting
with HONEYCOMB vs. those targeting prior platforms. Starting with Honeycomb, an application is not
in the killable state until its onStop() has returned. This impacts when onSaveInstanceState(Bundle)
may be called (it may be safely called after onPause() and allows and application to safely wait
until onStop() to save persistent state.


For those methods that are not marked as being killable, the activity's process will not be killed
by the system starting from the time the method is called and continuing after it returns.
Thus an activity is in the killable state, for example, between after onPause() to the start of onResume().

javadoc翻訳 〜Activity編〜(1)
javadoc翻訳 〜Activity編〜(2)
javadoc翻訳 〜Activity編〜(4)
javadoc翻訳 〜Activity編〜(5)
javadoc翻訳 〜Activity編〜(6)last
posted by sandman at 15:48| Comment(0) | Android | このブログの読者になる | 更新情報をチェックする




認証コード: [必須入力]