ActivityA.onResume()
이 (가) 호출되는 것으로 설명하는 동작이 올바르지 않습니다. AndroidManifest.xml 파일의 오타가 의심됩니다. 그것을 게시하고 우리에게 보여줄 수 있습니까?
onStop()
및 onDestroy()
의 타이밍은 조금 덜 정의됩니다. 다음은 작동하는 예제입니다. 그러나 onStop()
및 onDestroy()
은 사용자가 뒤로 버튼을 클릭 할 때까지 호출되지 않습니다 (단 onResume()
는 호출되지 않습니다). ActivityB를 시작한 후 finish()
으로 전화를하면 ActivityA가 먼저 호출됩니다. 마무리없이
OUTPUT()
D/HelloAndroidActivity(13113): [HelloAndroidActivity.java:19:onCreate()] onCreate()[email protected]
D/HelloAndroidActivity(13113): [HelloAndroidActivity.java:45:onStart()] onStart()[email protected]
D/HelloAndroidActivity(13113): [HelloAndroidActivity.java:39:onResume()] onResume()[email protected]
NEXT!
D/HelloAndroidActivity(13113): [HelloAndroidActivity.java:51:onPause()] onPause()[email protected]
D/GoodbyeAndroidActivity(13113): [GoodbyeAndroidActivity.java:16:onCreate()] onCreate()
D/GoodbyeAndroidActivity(13113): [GoodbyeAndroidActivity.java:32:onStart()] onStart()
D/GoodbyeAndroidActivity(13113): [GoodbyeAndroidActivity.java:26:onResume()] onResume()
D/HelloAndroidActivity(13113): [HelloAndroidActivity.java:57:onStop()] onStop()[email protected]
D/HelloAndroidActivity(13113): [HelloAndroidActivity.java:63:onDestroy()] onDestroy()[email protected]
[BACK]
D/GoodbyeAndroidActivity(13113): [GoodbyeAndroidActivity.java:38:onPause()] onPause()
D/GoodbyeAndroidActivity(13113): [GoodbyeAndroidActivity.java:44:onStop()] onStop()
D/GoodbyeAndroidActivity(13113): [GoodbyeAndroidActivity.java:50:onDestroy()] onDestroy()
HelloAndroidActivity.java :
public class HelloAndroidActivity extends Activity {
private static final String TAG = "HelloAndroidActivity";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
Log.d(TAG, "onCreate()" + this);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent i = new Intent(HelloAndroidActivity.this,
GoodbyeAndroidActivity.class);
startActivity(i);
// Uncomment this:
finish();
}
});
}
@Override
public void onResume() {
super.onResume();
Log.d(TAG, "onResume()" + this);
}
@Override
public void onStart() {
super.onStart();
Log.d(TAG, "onStart()" + this);
}
@Override
public void onPause() {
super.onPause();
Log.d(TAG, "onPause()" + this);
}
@Override
public void onStop() {
super.onStop();
Log.d(TAG, "onStop()" + this);
}
@Override
public void onDestroy() {
super.onStop();
Log.d(TAG, "onDestroy()" + this);
}
}
GoodbyeAndroidActivity.java :
public class GoodbyeAndroidActivity extends Activity {
private static final String TAG = "GoodbyeAndroidActivity";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
Log.d(TAG, "onCreate()");
super.onCreate(savedInstanceState);
setContentView(R.layout.goodbye);
}
@Override
public void onResume() {
super.onResume();
Log.d(TAG, "onResume()");
}
@Override
public void onStart() {
super.onStart();
Log.d(TAG, "onStart()");
}
@Override
public void onPause() {
super.onPause();
Log.d(TAG, "onPause()");
}
@Override
public void onStop() {
super.onStop();
Log.d(TAG, "onStop()");
}
@Override
public void onDestroy() {
super.onStop();
Log.d(TAG, "onDestroy()");
}
}
마무리
D/HelloAndroidActivity(13013): [HelloAndroidActivity.java:19:onCreate()] onCreate()[email protected]
D/HelloAndroidActivity(13013): [HelloAndroidActivity.java:45:onStart()] onStart()[email protected]
D/HelloAndroidActivity(13013): [HelloAndroidActivity.java:39:onResume()] onResume()[email protected]
NEXT!
D/HelloAndroidActivity(13013): [HelloAndroidActivity.java:51:onPause()] onPause()[email protected]
D/GoodbyeAndroidActivity(13013): [GoodbyeAndroidActivity.java:16:onCreate()] onCreate()
D/GoodbyeAndroidActivity(13013): [GoodbyeAndroidActivity.java:32:onStart()] onStart()
D/GoodbyeAndroidActivity(13013): [GoodbyeAndroidActivity.java:26:onResume()] onResume()
[BACK]
D/GoodbyeAndroidActivity(13013): [GoodbyeAndroidActivity.java:38:onPause()] onPause()
D/HelloAndroidActivity(13013): [HelloAndroidActivity.java:57:onStop()] onStop()[email protected]
D/HelloAndroidActivity(13013): [HelloAndroidActivity.java:63:onDestroy()] onDestroy()[email protected]
D/GoodbyeAndroidActivity(13013): [GoodbyeAndroidActivity.java:44:onStop()] onStop()
D/GoodbyeAndroidActivity(13013): [GoodbyeAndroidActivity.java:50:onDestroy()] onDestroy()
OUTPUT
main.xml에
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/hello_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<Button
android:id="@+id/button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="NEXT!"
/>
</LinearLayout>
goodbye.xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/hello_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Goodbye!!!"
/>
</LinearLayout>
의 AndroidManifest.xml : @Sam 퀘스트 답을 가지고 같은
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hello"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="10"/>
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name="com.example.hello.HelloAndroidActivity"
android:label="@string/app_name" android:noHistory="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.example.hello.GoodbyeAndroidActivity">
</activity>
</application>
</manifest>
나는 그것이 (전체 활동 라이프 사이클) 죽게해야 할 것 같아요. 이벤트 A가 해고되기 위해서는 액티비티 A가 화면에서 완전히 숨겨져 있어야합니다. 네가 활동 B를 시작하기 전에 finish()를 호출하기를 원하지 않는다면. – Samuel