我有兩個活動A和B,活動A從B開始並繼續運行。 我想從B發回一些仍在後臺運行的信息。android獲取運行活動的意圖
我正在這樣做,但B正在開始一個新的A活動,而不是使用前一個。
乙
Intent intent = new Intent();
intent.setClass(context, ObtenerDatos.class);
intent.putExtra("EXTRA_ID", StationID);
context.startActivity(intent);
finish();
和A獲取數據,因爲這:
@Override
public void onResume() {
super.onResume();
Bundle extras = getIntent().getExtras();
if (extras != null) {
String datas= extras.getString("EXTRA_ID");
if (datas!= null) {
// do stuff
}
}
}
我在做什麼錯?
謝謝!
Android按設計工作 - 畢竟,您明確開始了一項活動。如果這是返回結果,則在B中使用'setActivityResult'並在A中使用'onActivityResult'。由於A不可見,因此在B關閉之前真的沒有理由發送它的數據 - 如果您覺得需要這樣做,你做錯了什麼。 – 323go