私は写真専用のカスタムギャラリーを作成します。私は、このクラスでSDカードから写真を撮る:写真と写真を同期させる方法
public class Photos {
public static final String PHOTO_BUCKET_NAME =
Environment.getExternalStorageState().toString() + "/DCIM/Camera";
public static final int PHOTO_BUCKET_ID = getBucketId(PHOTO_BUCKET_NAME);
public static int getBucketId(String path) {
return path.toLowerCase().hashCode();
}
public static List<String> getPhotos(Context context) {
final String[] projection = {MediaStore.Images.Media.DATA};
final String selection = MediaStore.Images.Media.BUCKET_ID;
Cursor c = context.getContentResolver().query(Images.Media.EXTERNAL_CONTENT_URI, projection, selection, null, null);
List<String> result = new ArrayList<String>(c.getCount());
if (c.moveToFirst()) {
int dataColumn = c.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
do {
String data = c.getString(dataColumn);
result.add(data);
} while (c.moveToNext());
}
c.close();
return result;
}
そしてギャラリーに設定アダプター:
public class ImageAdapter extends BaseAdapter {
int GalItemBg;
private Context mContext;
private List<String> photoList;
public ImageAdapter(Context c) {
mContext = c;
photoList = Photos.getPhotos(c);
TypedArray typArray = obtainStyledAttributes(R.styleable.GalleryTheme);
GalItemBg = typArray.getResourceId(R.styleable.GalleryTheme_android_galleryItemBackground, 0);
typArray.recycle();
}
@Override
public int getCount() {
return photoList.size();
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView i = new ImageView(mContext);
Bitmap bm = BitmapFactory.decodeFile(photoList.get(position));
i.setImageBitmap(bm);
i.setLayoutParams(new Gallery.LayoutParams(80,70));
i.setScaleType(ImageView.ScaleType.FIT_XY);
i.setBackgroundResource(GalItemBg);
return i;
}
}
} 特別なものは何もありません。私は私のアプリを実行すると、すべてそれは動作します。その後、私はカメラを起動し、いくつかの写真を撮って、この時点で私のアプリはバックグラウンドで実行されています。私が自分のアプリに戻ってきたら、新しい写真を見る必要があります。どうやってするの?
が試み: 更新アダプタonResumeメソッドでは、このような:
Gallery g;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
g = (Gallery) findViewById(R.id.gallery);
g.setAdapter(new ImageAdapter(this));
}
@Override
public void onResume() {
g.setAdapter(new ImageAdapter(this));
}
アプリケーションがクラッシュ。私は何か間違っているかもしれませんか?
LogCat:
02-09 08:12:33.719: ERROR/AndroidRuntime(276): Uncaught handler: thread main exiting due to uncaught exception
02-09 08:12:34.129: ERROR/AndroidRuntime(276): java.lang.RuntimeException: Unable to resume activity {ru.home.tabexample/ru.home.tabexample.TabAct}: java.lang.RuntimeException: Unable to resume activity {ru.home.tabexample/ru.home.tabexample.FirstTab}: android.app.SuperNotCalledException: Activity {ru.home.tabexample/ru.home.tabexample.FirstTab} did not call through to super.onResume()
02-09 08:12:34.129: ERROR/AndroidRuntime(276): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2950)
02-09 08:12:34.129: ERROR/AndroidRuntime(276): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2965)
02-09 08:12:34.129: ERROR/AndroidRuntime(276): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2516)
02-09 08:12:34.129: ERROR/AndroidRuntime(276): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
02-09 08:12:34.129: ERROR/AndroidRuntime(276): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
02-09 08:12:34.129: ERROR/AndroidRuntime(276): at android.os.Handler.dispatchMessage(Handler.java:99)
02-09 08:12:34.129: ERROR/AndroidRuntime(276): at android.os.Looper.loop(Looper.java:123)
02-09 08:12:34.129: ERROR/AndroidRuntime(276): at android.app.ActivityThread.main(ActivityThread.java:4363)
02-09 08:12:34.129: ERROR/AndroidRuntime(276): at java.lang.reflect.Method.invokeNative(Native Method)
02-09 08:12:34.129: ERROR/AndroidRuntime(276): at java.lang.reflect.Method.invoke(Method.java:521)
02-09 08:12:34.129: ERROR/AndroidRuntime(276): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
02-09 08:12:34.129: ERROR/AndroidRuntime(276): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
02-09 08:12:34.129: ERROR/AndroidRuntime(276): at dalvik.system.NativeStart.main(Native Method)
02-09 08:12:34.129: ERROR/AndroidRuntime(276): Caused by: java.lang.RuntimeException: Unable to resume activity {ru.home.tabexample/ru.home.tabexample.FirstTab}: android.app.SuperNotCalledException: Activity {ru.home.tabexample/ru.home.tabexample.FirstTab} did not call through to super.onResume()
02-09 08:12:34.129: ERROR/AndroidRuntime(276): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2950)
02-09 08:12:34.129: ERROR/AndroidRuntime(276): at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:170)
02-09 08:12:34.129: ERROR/AndroidRuntime(276): at android.app.LocalActivityManager.dispatchResume(LocalActivityManager.java:518)
02-09 08:12:34.129: ERROR/AndroidRuntime(276): at android.app.ActivityGroup.onResume(ActivityGroup.java:58)
02-09 08:12:34.129: ERROR/AndroidRuntime(276): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1149)
02-09 08:12:34.129: ERROR/AndroidRuntime(276): at android.app.Activity.performResume(Activity.java:3763)
02-09 08:12:34.129: ERROR/AndroidRuntime(276): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2937)
02-09 08:12:34.129: ERROR/AndroidRuntime(276): ... 12 more
02-09 08:12:34.129: ERROR/AndroidRuntime(276): Caused by: android.app.SuperNotCalledException: Activity {ru.home.tabexample/ru.home.tabexample.FirstTab} did not call through to super.onResume()
02-09 08:12:34.129: ERROR/AndroidRuntime(276): at android.app.Activity.performResume(Activity.java:3765)
02-09 08:12:34.129: ERROR/AndroidRuntime(276): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2937)
02-09 08:12:34.129: ERROR/AndroidRuntime(276): ... 18 more
アクティビティでonresumeメソッドを実装し、この写真ユーティリティメソッドを呼び出して更新します。私はここに何かを逃していますか解決策はかなり明白ですから。 –
Thx。私はこれを試して、アプリがクラッシュした。申し訳ありません、私は初心者です=) – gerbit
クラッシュログを添付します。ケン – Varun