2016-11-15 83 views
0

這是可能的嗎?我的主要活動通過意圖傳遞圖像到putExtra的多個活動

routeListView.setOnItemClickListener(
      new AdapterView.OnItemClickListener() { 
       @Override 
       public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 

        String route = values[position]; 

        //for loop to increment through each route list item 
        int i; 
        for (i=0; i < values.length;i++) 
        { 
         int imageId = (int) image.getResourceId(i, -1); 
         if (route.equals(values[i])) 
         { 
          Intent intent = new Intent(view.getContext(),  RouteDetails.class); 
          intent.putExtra("route", routeDetail[i]); 
          intent.putExtra("imageResourceId", imageId); 
          startActivity(intent); 
         } 
        } 
       } 
      } 

有意向,現在我把它的形象傳遞給RouteDetails.class,但我也想相同的圖像傳遞給FullScreenImage.class。我想要打開路由詳細信息活動,但不是FullScreenImage活動。然後以後能夠從RouteDetails.class打開FullScreenImage.class活動有沒有一種簡單的方法來實現這一點?

+0

您可以簡單地將您的路由和imageResourceId傳遞給RouteDetails活動,然後將其傳遞給FullScreenImage活動。 –

+0

如何傳遞圖片資源ID。與語法 – user4297729

+0

一樣,您只需將它作爲int值傳遞,並以int值的形式獲取它也可以 –

回答

0
Pscudeo code:-- yes posssible . 
you can send it through intent to intent following like that or 
else if you have URL you can send that as a string . 

Send from Acitivity:--- 

Intent _intent = new Intent(this, newscreen.class); 
Bitmap _bitmap; // your bitmap 
ByteArrayOutputStream _bs = new ByteArrayOutputStream(); 
_bitmap.compress(Bitmap.CompressFormat.PNG, 50, _bs); 
i.putExtra("byteArray", _bs.toByteArray()); 
startActivity(i); 

Receive from Acitivity:-- 

if(getIntent().hasExtra("byteArray")) { 
    ImageView _imv= new ImageView(this); 
    Bitmap _bitmap = BitmapFactory.decodeByteArray(
     getIntent().getByteArrayExtra("byteArray"),0,getIntent().getByteArrayExtra("byteArray").length);   
    _imv.setImageBitmap(_bitmap); 
} 
相關問題