片段不会保留在android中

时间:2013-05-01 05:49:54

标签: android android-fragments fragment retain

我已实施fragmetation。我提到this。我的对象失去了价值......

我的代码

public ImageDetailsFragment(Data photo) {
    this.photo = photo;     
}

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

    setRetainInstance(true);

    if (mContext == null) {
        mContext = getActivity();
    }

    gv = (LinearLayout) inflater.inflate(R.layout.image_details, null);

    initAd(gv, R.id.adLayout);
    initTab(gv);

    return gv;
}


private void initTab(LinearLayout gv) {

    tvTitleText = (TextView) gv.findViewById(R.id.tvTitleText);
    tvTitleText.setTypeface(Utils.getBold(getActivity()));
    tvTitleText.setText(photo.name);
}


private void shareInstagram() {
    try {
        File file = new File(Environment.getExternalStorageDirectory()
                + "/tmp.jpg");

        if (file.exists() && file.isFile()) {
            Intent shareIntent = new Intent(Intent.ACTION_SEND);
                    shareIntent.setType("image/*");
                    shareIntent.putExtra(Intent.EXTRA_TEXT, "" + photo.name);
                    shareIntent.setPackage("com.instagram.android");
            shareIntent.putExtra(Intent.EXTRA_STREAM,
                    Uri.parse("file://" + file.getAbsolutePath()));
            startActivity(shareIntent);
        }
    } catch (Exception e) {
        e.printStackTrace();            
    }

}

我上面的代码运行正常。但是当我在Instagram上分享我的图像时,在回来后共享时它会因空指针异常而崩溃。

我的logcat

05-01 12:38:27.230: E/AndroidRuntime(7505): Caused by: java.lang.NullPointerException
05-01 12:38:27.230: E/AndroidRuntime(7505):     at weetech.alliswall.fragments.ImageDetailsFragment.initTab(ImageDetailsFragment.java:224)
05-01 12:38:27.230: E/AndroidRuntime(7505):     at weetech.alliswall.fragments.ImageDetailsFragment.onCreateView(ImageDetailsFragment.java:201)
05-01 12:38:27.230: E/AndroidRuntime(7505):     at android.support.v4.app.Fragment.performCreateView(Fragment.java:1460)
05-01 12:38:27.230: E/AndroidRuntime(7505):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:911)
05-01 12:38:27.230: E/AndroidRuntime(7505):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088)
05-01 12:38:27.230: E/AndroidRuntime(7505):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1070)
05-01 12:38:27.230: E/AndroidRuntime(7505):     at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1861)
05-01 12:38:27.230: E/AndroidRuntime(7505):     at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:547)
05-01 12:38:27.230: E/AndroidRuntime(7505):     at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1167)
05-01 12:38:27.230: E/AndroidRuntime(7505):     at android.app.Activity.performStart(Activity.java:5216)
05-01 12:38:27.230: E/AndroidRuntime(7505):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2073)
05-01 12:38:27.230: E/AndroidRuntime(7505):     ... 11 more

我认为照片对象被破坏或其他东西..如何保留? 还欢迎其他解决方案。

0 个答案:

没有答案