2017-07-16 9 views
0

ListViewをリフレッシュしたいと思います。私のサービスでは、私はオブジェクトのリストを準備しています。どのようにオブジェクトのリストを送信し、ListViewで受信するのですか?Androidブロードキャストオブジェクトリストの送受信方法

マイサービス

@Override 
    public void onLocationChanged(Location location) { 
    //populate list 
    //send list 
    sendLocationBroadcast(poiList); 
} 
private void sendLocationBroadcast(List<Poi> poiList) { 

     Intent locationIntent = new Intent(); 
     locationIntent.setAction(LOACTION_ACTION); 
     locationIntent.putExtra(LOCATION_MESSAGE, poiList.toString()); 

     LocalBroadcastManager.getInstance(this).sendBroadcast(locationIntent); 

} 

そしてメインの活動

@Override 
     public void onReceive(Context context, Intent intent) { 


      if (null != intent && intent.getAction().equals(LOACTION_ACTION)) { 

       String locationData = intent.getStringExtra(LOCATION_MESSAGE); 

       ArrayList<Poi> dataList = (ArrayList<Poi>) intent.getSerializableExtra("DATA_LIST"); 

      } 

     } 

これを修正するには?

答えて

1

変更

locationIntent.putExtra(LOCATION_MESSAGE, poiList.toString()); 

Bundle bundle = new Bundle(); 
bundle.putSerializable("data",poiList); 
locationIntent.putExtras(bundle); 

にデータ

if (getIntent().hasExtra("data")) { 
    Bundle bundle = getIntent().getExtras(); 
    if(bundle!=null) 
     ArrayList<Poi> dataList = (ArrayList<Venue>) bundle.getSerializable("arrayListVenue"); 
} 

を読み、確認するためにPoiオブジェクトであなたimplements Serializableその

関連する問題