2016-06-23 2 views
0

전에 this 질문을 게시했으며 결론은 앱의 라이프 사이클을 이해하기 위해 더 많은 디버그가 필요하다는 것입니다. 후속 조치가 있습니다. 실제로 더 혼란 스럽습니다.Android 애플리케이션 라이프 사이클 이해

Application.onCreate 메서드는 앱이 시작될 때 한 번, 한 번 닫힐 때마다 두 번 호출됩니다. 이 일이 일어날 예정입니까? 문제는 응용 프로그램이 시작될 때 시작하고 응용 프로그램이 종료 될 때 중지하려는 서비스가 있다는 것입니다. 두 상황 모두에서 onCreate이 호출 된 것 같습니다. 제발 조언.

참고 : 현재 백그라운드 실행에 관심이 없습니다.

편집 : 앱을 종료 할 때 Application.onCreateafer 주 활동의 Activity.onDestroy이라고합니다. 그게 어떻게 관련이 있을지 모르겠다. 혼란에 가담 할 뿐이다. 응용 프로그램은 이후에 "생성되었습니다"주 활동이 파괴 되었습니까? 말이되지 않습니다.

편집 : 여기에 샘플 로그를 남기십시오. 처음 앱을 실행 한 다음 '모두 지우기'를 탭하여 앱을 종료했습니다. 나는 이것이 서비스가 백그라운드에서 실행되도록 할 것이라고 믿는다. 이 로그는 앱을 두 번째 실행 한 로그입니다.

06-22 19 : 54 : 29.971 2504-2504이/com.demo.demochatdemo I/PhoneWindow : [generateLayout가 나는 닫을 대신 후라고하는 것이 onCreate이 때 응용 프로그램이 시작 호출되지 주목하라 ] setColorNavigationBar => color = 0x ff000001 06-22 19 : 54 : 29.981 2504-2504/com.demo.demochatdemo D/PhoneWindowEx : [PWEx] [generateLayout] setNavigationBarColor2 : colors = 0xff000000 06-22 19:54 : 29.981 2504-2504/com.demo.demochatdemo I/PhoneWindow : [setNavigationBarColor2] color = 0xff000000 06-22 19 : 54 : 30.001 2504-2504/com.demo.demochatdemo I/Activity : Activity.onPostResume() 06-22 19:54:30 2504-2504/com.demo.demochatdemo 0.011 나는/ViewRootImpl는 : 54 : CPU는 = 진정한 06-22 (19) 수직 동기화가 가능 렌더링 30.011 2504-3647/com.demo.demochatdemo D/OpenGLRenderer : 사용 EGL_SWAP_BEHAVIOR_PRESERVED : 사실 06 -22 19 : 54 : 30.021 2504-2504/com.demo.demochatdemo D/Atlas :지도 검증 중 ... 06-22 19 : 54 : 30.051 2504-3647/com.demo.demochatdemo I/Adreno-EGL : : EGL 1.4 QUALCOMM 빌드 : (Iac7c2e2837) 는 OpenGL ES 쉐이더 컴파일러 버전 : E031.25.03.04 빌드 날짜 : 07/08/15 수요일 지역 지점 : LA_BR_1_2_3_RB1_AU080_1285665 원격 지점 : 지역 패치 : 재구성 지점 : 06-22 19 : 54 : 30.051 2504-3647/com.demo.demochatdemo I/OpenGLRenderer : 초기화 된 EGL, 버전 1.4 06-22 19 : 54 : 30.061 2504-3647/com.demo.demochatdemo D/OpenGLRenderer : 디버그 모드 사용 0 06-22 19 : 54 : 30.161 2504-2504/com.demo.demochatdemo V/ViewRootImpl : 내용 그림 완료 : com.demo.demochatdemo/com.demo.demochatdemo.ContactActivity 06- 22 19 : 54 : 30.171 2504-2504/com.demo.demochatdemo 비활성 상태의 InputConnection에 대한 비활성 상태의 showStatusIcon 06-22 19 : 54 : 30.171 2504-2504/com.demo.demochatdemo I/Timeline : 타임 라인 : Activity_idle id : android.os.BinderProxy 31f3e056 시간 @ :

06-22 19 : 54 : 150,361,131

이 시점에서 나는 다음과 같은 응용 프로그램을 닫고 얻을 40.621 2,504에서 2,504 사이가/com.demo.demochatdemo I/활동 : Activity.onPostResume()은 06-22를 호출했습니다. 19 : 54 : 40.641 2504-2504/com.demo.demochatdemo I/Timeline : 타임 라인 : Activity_idle id : [email protected] 시간 : 150371603 06-22 19 : 54 : 46.861 4061-4061/com.demo.demochatdemo I/com.demo.demochatdemo.ContactActivity : onCreate

onCreate이 호출되고 있습니다.

편집 :

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.demo.demochatdemo"> 

    <application 
     android:allowBackup="true" 
     android:icon="@mipmap/ic_launcher" 
     android:label="@string/app_name" 
     android:supportsRtl="true" 
     android:theme="@style/AppTheme" 
     android:name="com.demo.demochatdemo.ChatApplication"> 

     <activity 
      android:name=".ContactActivity" 
      android:label="@string/app_name"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 

     <activity android:name=".ChatActivity"> 
     </activity> 

    </application> 

</manifest> 

편집 : 여기 매니페스트의 현재 활동에 대한 코드입니다.

공용 클래스 ContactActivity은 활동이 앱을 닫기 전에

+0

아마도 다른 응용 프로그램의 인스턴스가 생성되고 있습니다. 로그/추적을 생성하는 것이 좋습니다. 자세한 내용을 확인하려면 – meda

+0

@meda를 업데이트하십시오. 수정하십시오! –

+0

@ AndréFratelli 매니페스트 파일을 포함시킬 수 있습니까? –

답변

1

당신이 서비스를 중지 마십시오 Store.Delegate {

private static final String TAG = ContactActivity.class.getName(); 
private String displayName; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 

    super.onCreate(savedInstanceState); 

    ListView listView; 

    final ChatApplication chatApplication = (ChatApplication)getApplication(); 
    final ContactActivity contactActivity = this; 

    setContentView(R.layout.contact_view); 

    listView = (ListView) findViewById(R.id.contact_view); 
    listView.setAdapter(new ContactViewAdapter(this, chatApplication.getStores(), new View.OnTouchListener() { 

     @Override 
     public boolean onTouch(View view, MotionEvent motionEvent) { 

      if (MotionEvent.ACTION_UP == motionEvent.getAction()) { 

       Intent intent = new Intent(ContactActivity.this, ChatActivity.class); 

       TextView displayName = (TextView) view.findViewById(R.id.display_name); 
       CharSequence charSequence = displayName.getText(); 

       setDisplayName(charSequence.toString()); 

       intent.putExtra(ChatActivity.INTENT_EXTRA_STORE, charSequence); 

       startActivity(intent); 
      } 

      return true; 
     } 
    })); 
} 

}을 구현 확장? Service.onStartCommand()의 기본 구현은 START_STICKY를 반환합니다. 재정의하지 않으면 암시 적으로 Application 인스턴스를 강제로 시작하는 서비스가 다시 시작됩니다.

+1

당신이 옳을지도 모릅니다! 앱 종료 시점을 추적 할 메커니즘을 구현하지 않았기 때문에 서비스를 중단하지 않았습니다. 이제 ActivityLifecycleCallbacks와 플래그를 사용하여 활동이 활성화되었는지 여부를 추적합니다. 아직 많은 테스트를 수행하지는 않았지만이 문제를 아직 눈치 채지 못했습니다. 그건 완벽하게 이해가됩니다. 'onStartCommand'를 무시하고 알려 드리겠습니다. –

관련 문제