应用程序第四次在BackPressed第三次崩溃

时间:2015-08-12 06:20:31

标签: java android eclipse

我在Android应用程序中遇到一个奇怪的问题,我无法弄明白。是否有人可以帮助我解决这个问题。

让我描述一下我的应用和问题。

我从图库中获取所有图像,并使用适配器在gridview上显示它们。显示后,我将活动A的网格视图中的图像发送到下一个活动,点击gridview项目并在活动B中的图像视图上分配此图像...当我按下Bsck按钮从活动B返回活动A时,它工作正常。但是当我重复这个过程三到四次时,应用程序崩溃了。我不知道是什么问题。我确信问题出在活动A ..

以下是活动A的代码......

package info.androidhive.tabsswipe;

import android.content.Intent; 
import android.database.Cursor; 
import android.net.Uri; 
import android.os.Bundle; 
import android.provider.MediaStore; 
import android.support.v4.app.Fragment; 
import android.support.v4.app.LoaderManager.LoaderCallbacks; 
import android.support.v4.content.CursorLoader; 
import android.support.v4.content.Loader; 
import android.support.v4.widget.SimpleCursorAdapter; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.AdapterView; 
import android.widget.AdapterView.OnItemClickListener; 
import android.widget.GridView;

public class ImageLoader extends Fragment implements LoaderCallbacks<Cursor> {
    GridView gridView;
    SimpleCursorAdapter mAdapter;       
    Cursor cursor;
    Uri uri;
    String ID;
    Intent intent;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.videos, container, false);
        gridView = (GridView) getActivity().findViewById(R.id.gridView1);
        gridView.setAdapter(null);
        mAdapter = null;
        cursor = null;
        uri = null;
        ID = null;
        intent = null;
        mAdapter = new SimpleCursorAdapter(
            getActivity(),
            R.layout.gridview_item1,
            null,
            new String[] { "_data","_id"} ,
            new int[] { R.id.video_thumbnail_imageview},
            0
        );

        /** Setting adapter for the gridview */
        gridView.setAdapter(mAdapter);

        /** Loader to get images from the SD Card */
        getActivity().getSupportLoaderManager().initLoader(0, null, this);

        gridView.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // TODO Auto-generated method stub

                cursor = (Cursor)parent.getItemAtPosition(position);
                ID = cursor.getString(cursor.getColumnIndex("image_id"));
                intent = new Intent(getActivity(),Testing_Activity.class);
                intent.putExtra("Image_Path",ID);
                startActivity(intent);
            }
        });
        return rootView;
    }

    @Override
    public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
        /** Getting uri to the Thumbnail images stored in the external storage */
        uri = MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI;

        /** Invoking the uri */
        return new CursorLoader(getActivity(), uri, null, null, null, null);
    }

    /** A callback method, invoked after the requested content provider  returned all the data */
    @Override
    public void onLoadFinished(Loader<Cursor> arg0, Cursor arg1) {
        mAdapter.swapCursor(arg1);
    }

    @Override
    public void onLoaderReset(Loader<Cursor> arg0) {
        // TODO Auto-generated method stub
    }

}

有关此问题的任何帮助将受到高度赞赏。提前致谢。

0 个答案:

没有答案