1

当我尝试在浏览器上启动导航时,我的应用程序崩溃了。我读过一些关于实现 Parcelable 的内容(这里),但我不知道如何去做。

这是我第一次使用 Fragments,它们是 PIA。我通过添加另外两个选项卡修改了这个项目。

我得到的错误: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)

应用清单:

<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>

我得到错误的代码: 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();
        }
    }
  */

}

根据Android Reference,底部是 Parcelable 的“典型实现”,但是在互联网上查找了一些示例后,我无法实现它。

有人可以帮我吗?

4

2 回答 2

1

我猜你搞砸了活动的生命周期方法。当您启动 Google 地图时,您的活动的onPause()onSaveInstanceState()方法onStop()将被调用。有可能你把里面的东西搞砸了。我看不出你发布的内容有什么不好。

于 2013-11-15T10:41:45.943 回答
0

我已经打开了原始项目,并且该按钮在浏览器上启动了 Google 地图,而不会导致应用程序崩溃。某些东西可能会损坏。

于 2013-11-15T10:00:14.407 回答