この問題に関しては、ここ数日間問題が発生しています。 このコードセクションは、私が作成している音楽アプリのもので、主なアクティビティにあります。BroadcastReceiverは文字列を受信しますが、onresumeは値を持つtextViewを更新しません
これを除き、すべて正常に動作します。 画面がオンでアプリがフォアグラウンドにある場合、UIは新しい曲名でのみ更新されます。アプリがバックグラウンドにある場合、または画面がオフの場合、textViewは更新されません。画面が再びオンにされ、アプリがフォアグラウンドになったら、新しいトラックが再生されるまで待ってからtextViewを更新します。
なぜこれが理解される必要があるのですか? logcatは、簡単に電話天気をそれぞれの新しい曲のタイトルregaurdlessはまだ放送または電話で見ることができます
が本当に私のように狂気私を運転
@Override
protected void onPause() {
super.onPause();
LocalBroadcastManager.getInstance(this).unregisterReceiver(mMessageReceiver);
new IntentFilter("uiTrackUpdater");
Log.d("res", "on pause ");
}
/* onResume the app fires up and continues to work as expected.
however the textView is blank, because for some reason beyond
my understanding the songtitle that got received in the BroadcastReceiver
just wont show itself here.
*/
@Override
protected void onResume() {
super.onResume();
Intent intent = getIntent();
stit = intent.getStringExtra("songTitle");
TextView trackDetails = findViewById(R.id.sTitle);
trackDetails.setText(stit); //stit is always null onResume
LocalBroadcastManager.getInstance(this)
.registerReceiver(mMessageReceiver,
new IntentFilter("uiTrackUpdater"));
Log.d("res", "resumed");
}
/* the BroadcastReceiver works as expected. it picks up each new
song title that is being sent from a broadcast that is triggered
in a separate service class and while the screen is on or the app
is in the foreground then and only then does BroadcastReceiver update
the textView (trackdetails) but once the app is in the background or
the screen is off the BroadcastReceiver does not update the textView
*/
public BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
TextView trackDetails = findViewById(R.id.sTitle);
String songtitle = intent.getStringExtra("songTitle");
trackDetails.setText(songtitle);
/* the strange thing is this.
The Log.d clearly shows (ONLY in the "logcat pain") each new song title
that is currently being played even when the phone is in the
background, yet when I try to read from the songtitle variable
out from this BroadcastReceiver method the code show up as null.....
ありがとうバックグラウンド状態で携帯電話の画面をオフまたはアプリ内のNULL配信していますこのメソッドから曲のタイトルを得るために非常に多くの異なる方法を試しました
*/
Log.d("res","titleCount " + songtitle);
}
ここで私に人生のラインをキャストできるかどうかを知りたいだけです。 – krughanh