0
我是Android的新手。我想要做的是愚蠢的? 我有一個活動(EditPhoto)建立一個意向如下:如何建立活動的意圖和從片段接收
//Defining intent for loading image to the edit page
Intent recentPhoto = new Intent(this, ImportPhoto.class);
//Defining byte stream of image chosen
ByteArrayOutputStream bs = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.PNG, 50, bs);
//Transforming image to EditPhoto class in byte stream
recentPhoto.putExtra("byteArray", bs.toByteArray());
//Starting the intent
startActivity(recentPhoto);
,我試圖從另一個活動(ImportPhoto)片段(FirstFragment)收到如下圖所示:
// Getting the image back imported from EditPhoto page
final Bitmap photo = BitmapFactory.decodeByteArray(getIntent().
getByteArrayExtra("byteArray"),
0,getIntent().getByteArrayExtra("byteArray").length);
//Displaying the image in the image viewer
viewGalleryImages.setImageBitmap(photo);
由於片段類是靜態的,它說「無法對類型爲Activity」的非靜態方法getIntent()進行靜態引用。
我嘗試使用捆綁並將參數設置爲fragment,但又遭受同樣的問題。 ((ImportPhoto)getActivity())。getIntent ...這兩種方式運行的應用程序,但崩潰它。
任何形式的幫助將不勝感激。 在此先感謝。