最初は、カスタムリストビューを設定した後、FirebaseMessagingServiceのObjectアイテムを追加することを促すアイテムがリストビューに表示されなくなりました。 他のクラスやサービスのリストにObjectを追加できるように、私はlistView staticを宣言しました。 は、ここに私のコードです:FirebaseMessagingServiceからカスタムリストビューにオブジェクトを追加できません
FirebaseMessagingService:
@Override
public void onMessageReceived(final RemoteMessage remoteMessage) {
//Toast.makeText(getApplicationContext(), remoteMessage.getData().get("transaction"),Toast.LENGTH_SHORT).show();
Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {
@Override
public void run() {
Gson gson = new Gson();
Block b = gson.fromJson(remoteMessage.getData().get("transaction"), Block.class);
OpenChain.arrayList.add(b);
}
});
}
リストビューアクティビティコード:
public static ArrayList<Block> arrayList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_open_chain);
arrayList = new ArrayList<>();
getSupportActionBar().setTitle("Vote Ledger");
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
ListView listView = (ListView) findViewById(R.id.listView);
BlockchainAdap adap = new BlockchainAdap(this, arrayList);
listView.setAdapter(adap);
adap.notifyDataSetChanged();
}
**私はJSON形式 でクラウドからオブジェクトを受け付けております**また、内からオブジェクトを追加することができリストビューのアクティビティはFirebaseMessagingSerivceからではありません。