Plot: Unable to Mark Value - Fragments

advertisements

my app crashes when I try to launch navigation on browser. I've read something about implement Parcelable (here), but I don't have any idea on how to do it.

This is the first time I work with Fragments and they are a PIA. I've modified this project by adding two more tabs.

The error I got: LogCat:

    11-14 13:37:22.867: E/AndroidRuntime(671): FATAL EXCEPTION: main
11-14 13:37:22.867: E/AndroidRuntime(671): java.lang.RuntimeException: Parcel: unable to marshal value AppTabAFirstFragment{414df8c8 #0 id=0x1010000}
11-14 13:37:22.867: E/AndroidRuntime(671):  at android.os.Parcel.writeValue(Parcel.java:1235)
11-14 13:37:22.867: E/AndroidRuntime(671):  at android.os.Parcel.writeList(Parcel.java:622)
11-14 13:37:22.867: E/AndroidRuntime(671):  at android.os.Parcel.writeValue(Parcel.java:1195)
11-14 13:37:22.867: E/AndroidRuntime(671):  at android.os.Parcel.writeMapInternal(Parcel.java:591)
11-14 13:37:22.867: E/AndroidRuntime(671):  at android.os.Parcel.writeMap(Parcel.java:575)
11-14 13:37:22.867: E/AndroidRuntime(671):  at android.os.Parcel.writeValue(Parcel.java:1166)
11-14 13:37:22.867: E/AndroidRuntime(671):  at android.os.Parcel.writeMapInternal(Parcel.java:591)
11-14 13:37:22.867: E/AndroidRuntime(671):  at android.os.Bundle.writeToParcel(Bundle.java:1619)
11-14 13:37:22.867: E/AndroidRuntime(671):  at android.os.Parcel.writeBundle(Parcel.java:605)
11-14 13:37:22.867: E/AndroidRuntime(671):  at android.app.ActivityManagerProxy.activityStopped(ActivityManagerNative.java:2078)
11-14 13:37:22.867: E/AndroidRuntime(671):  at android.app.ActivityThread$StopInfo.run(ActivityThread.java:2874)
11-14 13:37:22.867: E/AndroidRuntime(671):  at android.os.Handler.handleCallback(Handler.java:615)
11-14 13:37:22.867: E/AndroidRuntime(671):  at android.os.Handler.dispatchMessage(Handler.java:92)
11-14 13:37:22.867: E/AndroidRuntime(671):  at android.os.Looper.loop(Looper.java:137)
11-14 13:37:22.867: E/AndroidRuntime(671):  at android.app.ActivityThread.main(ActivityThread.java:4745)
11-14 13:37:22.867: E/AndroidRuntime(671):  at java.lang.reflect.Method.invokeNative(Native Method)
11-14 13:37:22.867: E/AndroidRuntime(671):  at java.lang.reflect.Method.invoke(Method.java:511)
11-14 13:37:22.867: E/AndroidRuntime(671):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
11-14 13:37:22.867: E/AndroidRuntime(671):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-14 13:37:22.867: E/AndroidRuntime(671):  at dalvik.system.NativeStart.main(Native Method)

App Manifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.lupradoa.lakari"
    android:versionCode="1"
    android:versionName="1.0">
     <uses-permission android:name="android.permission.INTERNET" />

    <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="19" />

    <application android:label="@string/app_name"
        android:icon="@drawable/ic_launcher"
        android:theme="@style/AppTheme"
        android:allowBackup ="false">

        <activity android:name="com.lupradoa.lakari.base.AppMainTabActivity" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    <intent-filter>
    <action android:name="android.intent.action.SEND" />
    <category android:name="android.intent.category.DEFAULT" />
  </intent-filter>
    </application>

</manifest>

Code where I got the error: FragmentA.java:

    package com.lupradoa.lakari.fragmenttabstudy.tabA;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;

import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;

import com.lupradoa.lakari.R;
import com.lupradoa.lakari.base.BaseFragment;

public class AppTabAFirstFragment extends BaseFragment {
    private Button mGotoButton;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View view       =   inflater.inflate(R.layout.app_tab_a_first_screen, container, false);

        mGotoButton =   (Button) view.findViewById(R.id.goToShop);
        mGotoButton.setOnClickListener(listener);

        return view;
    }

    private OnClickListener listener        =   new View.OnClickListener(){
        @Override

        public void onClick(View v) {
            Intent navigation = new Intent(Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?f=d&daddr=42.338803,-7.863178"));

            navigation.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            try{
                startActivity(navigation);
            }catch(ActivityNotFoundException anf){
                Log.w(TAG, "Navigation not installed");
            }
        }
    };

    /*
    public static class MyParcelable implements Parcelable {
        private int mData;

        public int describeContents() {
            return 0;
        }

        public void writeToParcel(Parcel out, int flags) {
            out.writeInt(mData);
        }

        public static final Parcelable.Creator<MyParcelable> CREATOR
                = new Parcelable.Creator<MyParcelable>() {
            public MyParcelable createFromParcel(Parcel in) {
                return new MyParcelable(in);
            }

            public MyParcelable[] newArray(int size) {
                return new MyParcelable[size];
            }
        };

        private MyParcelable(Parcel in) {
            mData = in.readInt();
        }
    }
  */

}

At the bottom is the "typical implementation" of Parcelable according to Android Reference, but after looking in the internet for some samples, I wasn't able to implement it.

Can anybody help me, please?


I'm guessing that you've messed up your activity's lifecycle methods. When you launch Google Maps, your activity's onPause(), onSaveInstanceState() and onStop() methods will be called. It is possible that you have messed up something in there. I don't see anything bad with what you've posted.