2016-11-15 63 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); 
} 
相关问题