2017-11-29 13 views
0

오늘 Google Play 서비스 서비스를 최신 버전의 앱으로 업데이트했습니다. 이클립스는 나에게 어떤 종류의 오류도주지 않고있다. 나는 그것을 컴파일했다. 그리고 나는 나의 휴대 전화에서 테스트 할 때 잘 동작한다. 그런 다음 메뉴로 가서 종료를 선택하고 예를 선택하여 닫으면 앱이 화면에서 사라진다. 그러나 휴대 전화 하단에있는 사각형을 누르면 (열어 놓은 모든 앱을 나열 할 때) 앱이 계속 실행 중입니다! o_O앱을 종료 한 후에도 앱이 열려 있습니까? 뭐가 잘못 되었 니?

업데이트하기 전에 앱이 정상적으로 종료되었으며 종료 한 후에도 활성 상태로 유지됩니다. 하지만 GPS가 이런 종류의 문제를 일으킬 수 있다고 생각하지 않습니다. 어떠한 제안???

여기

package com.myapp.radio; 

import android.app.Activity; 
import android.app.AlertDialog; 
import android.content.ComponentName; 
import android.content.Context; 
import android.content.DialogInterface; 
import android.content.Intent; 
import android.content.ServiceConnection; 
import android.media.AudioManager; 
import android.os.Bundle; 
import android.os.IBinder; 
import android.view.Menu; 
import android.view.MenuItem; 
import com.myapp.radio.R; 

public class BaseActivity extends Activity { 

private Intent bindIntent; 
private RadioService radioService; 

private static boolean isExitMenuClicked; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    isExitMenuClicked = false; 

    // Bind to the service 
    bindIntent = new Intent(this, RadioService.class); 
    bindService(bindIntent, radioConnection, Context.BIND_AUTO_CREATE); 

    setVolumeControlStream(AudioManager.STREAM_MUSIC); 
} 

@Override 
protected void onResume() { 
    super.onResume(); 
    if (isExitMenuClicked == true) 
     finish(); 
} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    getMenuInflater().inflate(R.menu.main_menu, menu); 

    if (radioService.getTotalStationNumber() <= 1) { 
    } 
    return true; 
} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    Intent i; 

    final String thisClassName = this.getClass().getName(); 
    final String thisPackageName = this.getPackageName(); 

    if (item.getItemId() == R.id.radio) { 
     if (!thisClassName.equals(thisPackageName + ".MainActivity")) { 
      i = new Intent(this, MainActivity.class); 
      i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
      i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
      startActivity(i); 
      return true; 
     } 

    } else if (item.getItemId() == R.id.exit) { 
     String title = "Cerrar aplicación"; 
     String message = "¿Realmente desea salir?"; 
     String buttonYesString = "Si"; 
     String buttonNoString = "No"; 

     isExitMenuClicked = true; 

     AlertDialog.Builder ad = new AlertDialog.Builder(this); 
     ad.setTitle(title); 
     ad.setMessage(message); 
     ad.setCancelable(true); 
     ad.setPositiveButton(buttonYesString, 
       new DialogInterface.OnClickListener() { 
        @Override 
        public void onClick(DialogInterface dialog, int which) { 

         if (radioService != null) { 
          radioService.exitNotification(); 
          radioService.stop(); 
          radioService.stopService(bindIntent); 
          isExitMenuClicked = true; 
          finish(); 
         } 
        } 
       }); 

     ad.setNegativeButton(buttonNoString, null); 

     ad.show(); 

     return true; 

    } else if (item.getItemId() == R.id.about) { 
     if (!thisClassName.equals(thisPackageName + ".AboutActivity")) { 
      i = new Intent(this, AboutActivity.class); 
      startActivity(i); 
      return true; 
     } 

    } else if (item.getItemId() == R.id.facebook) { 
     if (!thisClassName.equals(thisPackageName + ".FacebookActivity")) { 
      i = new Intent(this, FacebookActivity.class); 
      startActivity(i); 
      return true; 
     } 
    } else if (item.getItemId() == R.id.twitter) { 
     if (!thisClassName.equals(thisPackageName + ".TwitterActivity")) { 
      i = new Intent(this, TwitterActivity.class); 
      startActivity(i); 
      return true; 
     } 
    } 
    return super.onOptionsItemSelected(item); 
} 

// Handles the connection between the service and activity 
private final ServiceConnection radioConnection = new ServiceConnection() { 
    @Override 
    public void onServiceConnected(ComponentName className, IBinder service) { 
     radioService = ((RadioService.RadioBinder) service).getService(); 
    } 

    @Override 
    public void onServiceDisconnected(ComponentName className) { 
     radioService = null; 
    } 
}; 

protected void onCreate1(Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 

} 

} 
+0

Android의 일반적인 동작입니다. 운영 체제는 앱을 닫은 후에도 메모리에 앱을 보관하도록 선택할 수 있습니다. 다양한 기기와 Android 버전이 이와 관련하여 다른 행동을 보일 수 있습니다. –

+0

Typo, MainActivity가 실제로 BaseActivity.java 인 것을 의미 할 때 – unarea

+0

@ScottKronheim은 ​​그것을 없애고 닫는 방법이 있습니까? 사용자가 휴대 전화에서 앱을 닫을 수있는 유일한 방법은 실행중인 프로세스를 확인하고 억류를 강요하거나 사각형을 누른 다음 앱의 오른쪽 상단 모서리에있는 X를 클릭하는 것입니다. – unarea

답변

0

이 문제는 Google Play 서비스와 관련이없는 (종료 메뉴 프로세스가 실행) 내 MainActivity.java이다,이 방법 안드로이드 작품이다.

응용 프로그램을 종료하면 얼마 동안 살아 있습니다. 실행중인 활동이 없지만 응용 프로그램 인스턴스가 활성 상태입니다. 그리고 짧은 시간 후에 다시 시작하면 이전 응용 프로그램에서 상속 된 일부 응용 프로그램 데이터가 매우 빨리 시작됩니다. 예를 들어 모든 정적 변수는 여전히 살아 있고 이전 값을 포함합니다. 다시 시작한 응용 프로그램에서 매우 복잡한 버그가 발생할 수 있으므로주의하십시오!

추가 생활 시간은 현재 조건에 따라 다릅니다. 충분한 메모리가있는 경우 - 길지 만 충분하지 않아 - 더 빨리 사망합니다.

+0

설명을 주셔서 감사합니다! 종료 후 "살아있는 모드"에있는 동안 팝업되는 광고는 어떤 방식 으로든 해결 될 수 있습니까? 앱이 실행중인 것으로 생각하고 백그라운드에서 삽입 광고를 시작하도록합니다. o_O – unarea

+0

@unarea, 내가 전에 쓴 것처럼, 살아있는 활동은 없지만 일부 배경 작업이 진행 중일 수 있습니다. 따라서 새 UI를 표시하지 않으려면 종료 전에 모든 작업을 명시 적으로 중지해야합니다. 중지 방법은 실제 처리에 따라 달라질 수 있습니다 : 스레드, AsyncTask, 처리기, 서비스 ... 부검 팝업을 실행중인 질문은 분명하지 않습니다. –

+0

일반적으로 광고 네트워크 (예 : AdMob)는 임의의 순간에 삽입 광고를 게재하는 것을 금지합니다. 그것은 네트워크에 의해 금지되는 직접적인 방법입니다! 따라서 일반적인 규칙에 따라 광고는 일부 사용자 행동 (예 : 일부 버튼 누르기)에 대한 반응으로 표시되어야합니다. 광고와 관련된 앱의 행동을 수정해야 할 수도 있습니다 ... –