私は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() への静的参照を作成できません」と表示されます。
バンドルを使用して引数をフラグメントに設定しようとしましたが、同じ問題に再び悩まされました。
また、getActivity().getIntent.... を試してみましたが、getActivity を次のようにキャストしました ((ImportPhoto)getActivity()).getIntent... どちらの方法でもアプリケーションは実行されますが、クラッシュします。
あらゆる種類の助けをいただければ幸いです。前もって感謝します。