비 활동의 새 활동에서 대화 상자를 열려면 어떻게합니까? 카운트 다운 타이머를 실행하는 서비스가 있으며 카운트 다운 타이머가 완료되면 주요 활동에서 대화 상자를 열고 싶습니다. 나는 이것을 알아낼 수없는 것 같다. 정상적으로 작동하지 않는 경고 대화 상자를 설정하려고 시도했으며 추가 및 번들로 의도를 보내려고 시도했지만 여전히 운이 없습니다. 나는 Google에서 도움을 검색했으며이 링크 의 솔루션에 지쳤습니다 .
@Override
public void onFinish() {
Log.i(TAG, "Timer finished");
cdt.start();
showNotification();
addpoints();
savepref();
Intent intent = new Intent(BroadcastService.this, MainActivity.class);
Bundle bundle = new Bundle();
bundle.putInt("alert_icon_res_id", android.R.drawable.ic_dialog_info);
bundle.putString("alert_title", "Some Title");
bundle.putString("alert_message", "Some message");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
};
cdt.start();
}
여기에 주요 활동 코드 :
setContentView(R.layout.activity_main);
startService(new Intent(this, BroadcastService.class));
Log.i(TAG, "Started service");
Bundle b = getIntent().getExtras();
if (b != null && b.containsKey("alert_icon_res_id")) {
int icon = b.getInt("alert_icon_res_id");
String title = b.getString("alert_title");
String message = b.getString("alert_message");
new AlertDialog.Builder(this).setIcon(icon)
.setTitle(title).setMessage(message)
.setPositiveButton("Close", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}).create().show();
}
에서 OnFinish
당신은 의도에 번들을 넣어하지 않았습니다.
이 시도:
Bundle bundle = new Bundle();
bundle.putInt("alert_icon_res_id", android.R.drawable.ic_dialog_info);
bundle.putString("alert_title", "Some Title");
bundle.putString("alert_message", "Some message");
intent.putExtras(bundle); // add this line
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다