0
다음과 같은 경우가 있습니다. 활동 A는 활동 B를 시작합니다. B는 다른 활동 C가 시작된 통지를 클릭합니다. 이제는 진저 브레드와 ICS에서 그 행동이 다릅니다. Gingerbread의 Incase를 클릭하면 예상되는 동작이 표시되지만 ICS 또는 JellyBean에서 동일한 코드를 실행하면 알림 활동 A가 삭제됩니다 (OnDestroy가 호출 됨). 라이프 사이클 동작이 다른 이유는 무엇입니까? 모든 기기에서 일관된 방식으로 작동하도록하려면 어떻게해야합니까? 제발 제안 해주세요.활동주기가 다르게 동작합니다.
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.v("MyLog","Activity A created");
}
@Override
protected void onDestroy() {
super.onDestroy();
Log.v("MyLog","Activity A destroyed");
}
public void startB(View v)
{
Intent intent=new Intent(getApplicationContext(),B.class);
startActivity(intent);
}
protected void onStop()
{
super.onStop();
Log.v("MyLog","Activity A stopped");
}
protected void onResume()
{
super.onResume();
Log.v("MyLog","Activity A resumed");
}
}
}
public class B extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.b);
Log.v("MyLog","Activity B created");
}
protected void onStop()
{
super.onStop();
Log.v("MyLog","Activity B stopped");
}
protected void onResume()
{
super.onResume();
Log.v("MyLog","Activity B resumed");
}
public void startNotification(View v)
{
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(getApplicationContext())
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle("My notification")
.setContentText("Hello World!")
.setAutoCancel(true);
// Creates an explicit intent for an Activity in your app
Intent resultIntent = new Intent(getApplicationContext(), C.class);
// The stack builder object will contain an artificial back stack for the
// started Activity.
// This ensures that navigating backward from the Activity leads out of
// your application to the Home screen.
TaskStackBuilder stackBuilder = TaskStackBuilder.create(getApplicationContext());
// Adds the back stack for the Intent (but not the Intent itself)
stackBuilder.addParentStack(C.class);
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// mId allows you to update the notification later on.
int mId=1;
mNotificationManager.notify(mId, mBuilder.build());
}
}
public class C extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.c);
Log.v("MyLog","Activity C created");
}
protected void onStop()
{
super.onStop();
Log.v("MyLog","Activity C stopped");
}
protected void onResume()
{
super.onResume();
Log.v("MyLog","Activity C resumed");
}
}
예, 동의,하지만 나는 그것을 다르게 때때로이어야 행동을 기대할 수 있습니다,하지만 동일한 결과 매번를 얻을, 나는 하나는 안드로이드 2.3.3과 함께 만든, 너무 에뮬레이터의 두 가지 버전으로 동일한을 확인했습니다 다른 4.1.2. 활동 A는 4.1.2 장치/에뮬레이터에서 각각 파괴됩니다. Developers Guide에는이 동작에 대한 언급이 없습니다. 그것이 나를 괴롭히는 것입니다. – Ricky
게시 한 코드와 동일하게 확인할 수 있습니다. 동일한 사항을 준수 할 경우 알려 주시기 바랍니다. – Ricky
나는 "왜"를 모른다 - 미안. 문서는 백그라운드에서 모든 것이 포 그라운드 서비스를 포함하여 언제든지 죽을 수 있다고 말합니다. 레이아웃이나 큰 메모리 객체에서 큰 비트 맵을 사용하지 않습니까? – piotrpo