私は Android 開発の初心者で、タスクとアクティビティに関するドキュメントを読んだ後、アプリケーションを正しく動作させることができません。
(まず、私の英語でごめんなさい)
私のアプリケーションはLOGINとNEWSの 2 つのアクティビティで構成されています。どちらのアクティビティの起動方法も singleTask です。
NEWSアクティビティはAndroid通知チュートリアルの標準通知コードでonCreateで通知を作成します!
int icon = R.drawable.notification_icon; // icon from resources
CharSequence tickerText = "Hello"; // ticker-text
long when = System.currentTimeMillis(); // notification time
Context context = getApplicationContext(); // application Context
CharSequence contentTitle = "My notification"; // expanded message title
CharSequence contentText = "Hello World!"; // expanded message text
Intent notificationIntent = new Intent(this, MyClass.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
Notification notification = new Notification(icon, tickerText, when);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
最初にアプリケーションを開いたとき:
ログイン--> onResume() --> NEWS --> onCreate() --> 通知
コード付き
Intent newLogAct = new Intent(Login.this, News.class);
TomTuckerActivity.this.startActivity(newLogAct);
Back * NEWS *を叩くと破壊され、再び:
ログイン--> onResume() --> NEWS --> onCreate() --> 通知
(私はそのループが好きではありません、それを使用する理由は最後に説明されています)
ホームをクリックすると、メインメニューに戻り、ここから理解できないことを始めます。
通知を使用してアプリケーションを再起動しても問題はなく、onCreate を呼び出さずに通知を送信せずにNEWSウィンドウが再度開かれます。
NEWSを呼び出すときにアプリケーション アイコンを使用すると、onCreate() が再度呼び出されて通知が再度送信されるため、singleTask オプションは役に立たないようです。
私が望むのは、通知またはアイコンを使用して、残したアプリケーションを回復することです。
newLogAct のフラグで問題を解決できますか?
両方のアクティビティで singleTask 起動オプションを使用しても問題ありませんか?
戻るボタンのループ問題について:
ループを回避するために、onResume() の代わりに onCreate() を使用することを考えました。ただし、アプリケーション アイコンでアプリケーションを再起動すると、LOGINはロードされますが、onCreate は呼び出されないため、NEWSはロードされません。
それを解決する他の方法はありますか?
多分 onNewIntent() メソッドで?