Okey, 이상합니다. 두 가지 활동 (음, 둘 이상이지만 중요하지 않음) - AppActivity 및 PopupActivity. AppActivity는 내 응용 프로그램 활동이며 내 응용 프로그램 설정을 포함합니다. PopupActivity는 사용자가 알림 버튼을 클릭하면 열리는 대화 상자입니다 (RemoteViews 알림). 음, 작동합니다. 훌륭하게 작동합니다. 그러나 사용자가 백 버튼을 클릭하여 AppActivity를 닫은 경우에만 가능합니다. 그들이 가정을 클릭하면 단추를 클릭 한 후 몇 초 후에 PopupActivity가 열립니다. 사용자가 집 버튼으로 PopupActivity를 닫을 때도 같은 결과가 발생합니다. 알림의 버튼을 클릭해도 PopupActivity가 즉시 열리는 것은 아니지만 백그라운드의 어딘가에 남아있는 이전 활동을 종료하는 데 몇 초가 걸립니다.사용자가 홈 버튼을 클릭 할 때 활동이 중단됩니다.
onStop 및 onPause 메서드에서 finish()를 호출했지만 문제가 해결되지 않았습니다.
편집 : 여기의 코드 내가 가진 :
매니페스트 (사용자가 통지에서 버튼을 클릭 할 때 호출되는 단지 기능)
<activity
android:name="cc.lupine.quicksocial.AppActivity"
android:label="@string/app_name"
android:configChanges="orientation|screenSize" android:noHistory="true" android:clearTaskOnLaunch="true" android:finishOnTaskLaunch="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:configChanges="orientation|screenSize"
android:excludeFromRecents="true"
android:showOnLockScreen="false"
android:theme="@android:style/Theme.Holo.Light.Dialog.NoActionBar.MinWidth"
android:name="cc.lupine.quicksocial.PopupActivity"
android:noHistory="true"
android:launchMode="singleInstance"
android:taskAffinity=""
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<service android:name="cc.lupine.quicksocial.ShareService"></service>
ShareService.java :
public static void startSharing(Context ctx, int n) {
Log.d("sn", "startsharing called in shareservice");
if(n == 1 || n == 2)
{
Intent i = new Intent(ThisApplication.getAppContext(), PopupActivity.class);
i.putExtra("shareType", n);
i.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY|
Intent.FLAG_ACTIVITY_CLEAR_TOP|
Intent.FLAG_ACTIVITY_SINGLE_TOP|
Intent.FLAG_ACTIVITY_CLEAR_TASK|
Intent.FLAG_FROM_BACKGROUND|
Intent.FLAG_ACTIVITY_NEW_TASK);
ctx.startActivity(i);
} else if(n == 3) {
// doesn't matter for now
}
}
PopupActivity.java (단편) :
public class PopupActivity extends Activity implements OnDataPass {
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.d("sn", "oncreate called in popupactivity");
super.onCreate(savedInstanceState);
instanceOfPopupActivity = this;
setContentView(R.layout.activity_popup);
ShareFragment sfrag = new ShareFragment();
Bundle args = new Bundle();
Bundle extras = getIntent().getExtras();
try {
//doesn't matter
} catch(Exception e) { e.printStackTrace(); finish(); }
sfrag.setArguments(args);
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.contFragment, sfrag);
fragmentTransaction.commit();
}
@Override
public void onPause()
{
Log.d("sn", "onpause called in popupactivity");
finish();
super.onPause();
}
@Override
public void onStop() {
Log.d("sn", "onstop called in popupactivity");
super.onStop();
}
@Override
public void onDestroy()
{
Log.d("sn", "ondestroy called in popupactivity");
super.onDestroy();
}
}
그리고 나는 처음으로 팝업 열면 :
05-26 14:37:14.149: D/sn(7218): startsharing called in shareservice
05-26 14:37:14.179: D/sn(7218): oncreate called in popupactivity
을하지만 홈 버튼으로 팝업을 닫고 다시 열 때 :
05-26 14:38:11.620: D/sn(7218): startsharing called in shareservice
05-26 14:38:14.103: D/sn(7218): oncreate called in popupactivity
그것은이 소요 onCreate를 호출 할 시간이 많습니다. 그리고 지금, 이유가 무엇입니까?
나는 onPause와 onStop, AppActivity, PopupActivity 및 둘 다에서 finish()를 호출 해 보았습니다. onPause/onStop은 홈 버튼이 클릭 될 때마다 트리거되고 finish()는 호출되지만 여전히 내 문제는 해결되지 않습니다 –
System.err.println ("HI!"); HOME 버튼 클릭을 감지하는 방법에 넣으십시오. 나는 당신이 그것을 제대로 감지하지 못하고 있다고 생각합니다. 완료되면 응용 프로그램이 닫히고, 작동하지 않는 방법은 없습니다. – Dejan
집 버튼 클릭을 감지하지 못했습니다. 너무 까다로울뿐 아니라 사용자가 멀티 태스킹 메뉴를 사용하여 다른 앱으로 전환 할 때 작업을 포함하지 않습니다. 그래서 onPause 나 onStop에서 finish()를 호출합니다. 전경을 떠날 때마다 액티비티를 파괴하고 싶습니다. –