こんにちは frnds は、fragmentActivity をロードするアプリケーションを開発しています。フラグメント アクティビティには、4 つのタブを持つタブホストが含まれ、各タブはフラグメントをロードします。アプリケーションを実行すると、アプリケーションはスムーズに動作しますが、ホームボタンを押すか、他のアプリを実行すると、アプリケーションがクラッシュします... .
これは私の丸太猫です
09-12 05:47:39.055: E/AndroidRuntime(3692): FATAL EXCEPTION: main
09-12 05:47:39.055: E/AndroidRuntime(3692): java.lang.RuntimeException: Parcel: unable to marshal value WelcomeFragment{40d3ae00}
09-12 05:47:39.055: E/AndroidRuntime(3692): at android.os.Parcel.writeValue(Parcel.java:1235)
09-12 05:47:39.055: E/AndroidRuntime(3692): at android.os.Parcel.writeList(Parcel.java:622)
09-12 05:47:39.055: E/AndroidRuntime(3692): at android.os.Parcel.writeValue(Parcel.java:1195)
09-12 05:47:39.055: E/AndroidRuntime(3692): at android.os.Parcel.writeMapInternal(Parcel.java:591)
09-12 05:47:39.055: E/AndroidRuntime(3692): at android.os.Parcel.writeMap(Parcel.java:575)
09-12 05:47:39.055: E/AndroidRuntime(3692): at android.os.Parcel.writeValue(Parcel.java:1166)
09-12 05:47:39.055: E/AndroidRuntime(3692): at android.os.Parcel.writeMapInternal(Parcel.java:591)
09-12 05:47:39.055: E/AndroidRuntime(3692): at android.os.Bundle.writeToParcel(Bundle.java:1627)
09-12 05:47:39.055: E/AndroidRuntime(3692): at android.os.Parcel.writeBundle(Parcel.java:605)
09-12 05:47:39.055: E/AndroidRuntime(3692): at android.app.ActivityManagerProxy.activityStopped(ActivityManagerNative.java:2252)
09-12 05:47:39.055: E/AndroidRuntime(3692): at android.app.ActivityThread$StopInfo.run(ActivityThread.java:3052)
09-12 05:47:39.055: E/AndroidRuntime(3692): at android.os.Handler.handleCallback(Handler.java:725)
09-12 05:47:39.055: E/AndroidRuntime(3692): at android.os.Handler.dispatchMessage(Handler.java:92)
09-12 05:47:39.055: E/AndroidRuntime(3692): at android.os.Looper.loop(Looper.java:137)
09-12 05:47:39.055: E/AndroidRuntime(3692): at android.app.ActivityThread.main(ActivityThread.java:5041)
09-12 05:47:39.055: E/AndroidRuntime(3692): at java.lang.reflect.Method.invokeNative(Native Method)
09-12 05:47:39.055: E/AndroidRuntime(3692): at java.lang.reflect.Method.invoke(Method.java:511)
09-12 05:47:39.055: E/AndroidRuntime(3692): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
09-12 05:47:39.055: E/AndroidRuntime(3692): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
09-12 05:47:39.055: E/AndroidRuntime(3692): at dalvik.system.NativeStart.main(Native Method)
これは私のtabActivityです
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
actionBar = getSupportActionBar();
actionBar.setDisplayShowCustomEnabled(true);
View absView=LayoutInflater.from(this).inflate(R.layout.abs_layout, null);
actionBar.setCustomView(absView);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(false);
setContentView(R.layout.activity_tab_layout);
tabHost =(TabHost) findViewById(R.id.myTabHost);
tabHost.setup();
if (savedInstanceState != null) {
initializeTabHost();
tabHost.setCurrentTabByTag(savedInstanceState.getString("tab"));
backStacks=(HashMap<String, Stack<Fragment>>) savedInstanceState.getSerializable("stacks");
}
else
{
backStacks = new HashMap<String, Stack<Fragment>>();
for(int i=0;i<stackKey.length;i++)
backStacks.put(stackKey[i], new Stack<Fragment>());
initializeTabHost();
}
}
@Override
protected void onSaveInstanceState(Bundle outState) {
// super.onSaveInstanceState(outState);
outState.putString("tab", tabHost.getCurrentTabTag());
outState.putSerializable("stacks", backStacks);
}
private void initializeTabHost() {
tabHost.setOnTabChangedListener(this);
addTab(this, stackKey[0], labels[0],WelcomeFragment.class,R.drawable.menu_home);
addTab(this, stackKey[1], labels[1], ShopListFragment.class, R.drawable.menu_shops);
addTab(this, stackKey[2], labels[2], MyDealsFragment.class, R.drawable.menu_mydeals);
addTab(this, stackKey[3], labels[3], MyProfileFragment.class, R.drawable.menu_profile);
addTab(this, stackKey[4], labels[4], SettingFragment.class, R.drawable.menu_settings_on);
}
private void addTab(TabActivity activity,String tag,int label,Class<?> class1, int image)
{
Stack<Fragment> backStack = backStacks.get(tag);
View tabView=createTabView(label, image);
TabSpec tabSpec = tabHost.newTabSpec(tag).setIndicator(tabView).setContent(activity.new TabFactory(activity));
Fragment fragment = (Fragment) Fragment.instantiate(activity, class1.getName(),null);
if(backStack.isEmpty())
if(fragment!=null)
backStack.push(fragment);
tabHost.addTab(tabSpec);
}
これが私の WelcomeFragment です
public class WelcomeFragment extends Fragment
{
ViewPageAdapter mAdapter;
ViewPager mPager;
CirclePageIndicator mIndicator;
List<Fragment> fragments;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.frag_welcome_layout,null);
mPager=(ViewPager)view.findViewById(R.id.myViewPager);
mIndicator=(CirclePageIndicator)view.findViewById(R.id.circlePageIndicator1);
mAdapter = new ViewPageAdapter(getActivity());
mPager.setAdapter(mAdapter);
mIndicator.setViewPager(mPager);
return view;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}