在牛轧糖中的TransactionTooLargeException [英] TransactionTooLargeException in Nougat

查看:895
本文介绍了在牛轧糖中的TransactionTooLargeException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

异常

  05-12 15:42:45.791 11043-11043 / E / UncaughtException:java.lang.RuntimeException: android.os.TransactionTooLargeException:data parcel size 631792 bytes 
at android.app.ActivityThread $ StopInfo.run(ActivityThread.java:3776)
at android.os.Handler.handleCallback(Handler.java:751 )
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread。 main(ActivityThread.java:6123)
在java.lang.reflect.Method.invoke(本地方法)
在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:867)
。在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)
。通过致:android.os.TransactionTooLargeException:data parcel size 631792 bytes
at android.os.BinderProxy.transactNative(Native Method)
at android.os.BinderProxy.transact(Binder.java:615)
at android.app.ActivityManagerProxy.activityStopped(ActivityManagerNative.java:3700)
at android.app.ActivityThread $ StopInfo.run(ActivityThread.java:376 8)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper .loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6123)
at java.lang.reflect.Method.invoke(Native Method)
在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:867)
在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)
05- 12 15:42:47.247 11043-11043 / E / A ndroidRuntime:FATAL EXCEPTION:main
进程:,PID:11043
android.app.ActivityThread $ StopInfo中的java.lang.RuntimeException:数据区大小631792字节
。运行(ActivityThread.java:3776)
在android.os.Handler.handleCallback(Handler.java:751)
在android.os.Handler.dispatchMessage(Handler.java:95)
在android.os.Looper.loop(Looper.java:154)
在android.app.ActivityThread.main(ActivityThread.java:6123)
(com.android.internal)
。 os.ZygoteInit.main(ZygoteInit.java:757)
导致:android.os.TransactionTooLargeException:数据宗地大小631792字节
在android.os.BinderProxy.transactNative(本地方法)
at android.os.BinderProxy.transact(Binder.java:615)
at android.app.ActivityManagerProxy.activityStopped(ActivityManagerNative.java:3700)
at android.app.ActivityThread $ StopInfo.run(ActivityThread.java:3768)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler。 java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6123)
at java.lang .reflect.Method.invoke(本机方法)维持在com.android.internal.os.ZygoteInit com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:867)

。主(ZygoteInit.java:757)

片段OnItemClick: -

  listview.setOnItemClickListener(new AdapterView.OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?>父视图,视图视图,int位置,
long id){

Bundle bundle = new Bundle();
ProdModel mProdModel = prodList.get(position);
bundle.putSerializable(object,mProdModel);
Intent intent = new Intent(getActivity(),DetailActivity.class);
intent.putExtra(bundle,bundle);
startActivityForResult(intent,1);

}

});

在DetailActivity中,

  Bundle bundle = getIntent()。getBundleExtra(bundle); 
if(bundle!= null){
ProdModel model =(ProdModel)bundle.getSerializable(object);



DetailActivity清单,

 < activity 
android:name =com.mass.mysample.DetailActivity
android:screenOrientation =portrait/>

使用Picasso加载图片



<$ p $ ()。$())$ b $ .b(.drawable.logo_without)
.fit()。into(productimage);

模型类

  public class ProdModel实现Serializable {
private String seller_id;
字符串名称;
私人字符串图像;
私人浮动价格;
私人浮动特价;
private String entity_id;
private String productNumQuantity;
私人字符串storetitle;
私有字符串描述;
私人字符串折扣;
私人字符串max_price;
私人字符串store_name;
private String StoreUrl;

public String getProductNumQuantity(){
return productNumQuantity;
}

public void setProductNumQuantity(String productNumQuantity){
this.productNumQuantity = productNumQuantity;
}

public String getDiscount(){
return discount;
}

public void setDiscount(String discount){
this.discount = discount;
}

public String getMax_price(){
return max_price;
}

public void setMax_price(String max_price){
this.max_price = max_price;
}

public String getStore_name(){
return store_name;
}

public void setStore_name(String store_name){
this.store_name = store_name;
}

public String getStoreUrl(){
return StoreUrl;
}

public void setStoreUrl(String storeUrl){
StoreUrl = storeUrl;
}

public String getStoretitle(){
return storetitle;
}

public void setStoretitle(String storetitle){
this.storetitle = storetitle;
}

public String getSeller_id(){
return seller_id;
}

public void setSeller_id(String seller_id){
this.seller_id = seller_id;
}

public String getName(){
return name;
}

public void setName(String name){
this.name = name;
}

public String getImage(){
return image;
}

public void setImage(String image){
this.image = image;
}

public String getEntity_id(){
return entity_id;
}

public void setEntity_id(String entity_id){
this.entity_id = entity_id;
}

public String getDescription(){
return description;
}

public void setDescription(String description){
this.description = description;
}

public float getPrice(){
return price;
}

public void setPrice(float price){
this.price = price;
}

public float getSpecialPrice(){
return specialprice;
}

public void setSpecialPrice(float specialprice){
this.specialprice = specialprice;






$ b

数据从TabActivity流向片段,

  1.我有ViewPager和Fragment的TabActivity。 
2.在Fragment中,我有一个ListView。
3.要分片的数据通过设置参数从视图寻呼机适配器传递。

我试过的解决方案

  1.一个实现序列化的POJO类。 
2.我使用Picasso从图片URL加载图片。
3.当片段中的ListView上的OnItemClick将数据传递给DetailActivity以显示所有传递的数据时,抛出此异常。
4.I在DetailActivity加载的图像和其他数据之后得到这个异常,然后app突然崩溃。
5.我在Intent中传递数据都是带有Id,Name,Image URL,Price等的POJO Object,

注意: -
仅在 NOUGAT中崩溃



最后,我实施的修复程序



将targetSdkVersion从25改为23



我的应用程序也不会在Nougat中崩溃。



所有我必须知道的是这个正确的解决方案,或者是否有任何解决方法。



请指导正确的方法。



预先致谢。



片段

  public class ProdFragment extends Fragment {
ListView listview;
SharedPreferences spref;
布尔isInternetPresent = false;
ConnectionDetector cd;

private String toBeDisplayed,CatID;
private static final String TAG = ProdFragment.class.getSimpleName();
字符串totalProductCart;
private ArrayList< Root_SubCatModel> subCatList;
private ArrayList< ProdModel>产品数;
ProdAdapter适配器;
$ b $ public ProdFragment(){
//必需的空公共构造函数
}

@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
spref = getActivity()。getSharedPreferences(getResources()。getString(R.string.myPref),
Context.MODE_PRIVATE);
Bundle bundle = getArguments();
if(bundle!= null){
int tabPosition = bundle.getInt(Tab_Position);
toBeDisplayed = bundle.getString(Tab_ToBeDisplayed);
CatID = bundle.getString(CategoryId);
subCatList =(ArrayList< Root_SubCatModel>)bundle.getSerializable(Tab_Data);
}
}

@Override
public查看onCreateView(LayoutInflater inflater,ViewGroup容器,Bundle savedInstanceState){
final查看rootView = inflater.inflate( R.layout.prod_listview,container,false);

cd = new ConnectionDetector(getActivity());
listview =(ListView)rootView.findViewById(R.id.prodlist);
if(subCatList!= null){
adapter = new ProdAdapter(getActivity(),
CatID,
toBeDisplayed,
R.layout.list_product,
subCatList,
(ProductCartCountListener)getActivity());
listview.setAdapter(adapter);
adapter.notifyDataSetChanged();

prodList = new ArrayList<>();
for(int i = 0; i< subCatList.size(); i ++){
if(subCatList.get(i).getProd()!= null){
if(toBeDisplayed .get()){
this.prodList = subCatList.get(i).getProd() ;
}
} else if(toBeDisplayed.equals(Products)){
this.prodList = subCatList.get(i).getProd();
}
}
}

}

listview.setOnItemClickListener(new AdapterView.OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent,View view,int position,
long id){

Bundle bundle = new Bundle();
bundle。 putSerializable(object,prodList.get(position));
Intent intent = new Intent(getActivity(),DetailActivity.class);
intent.putExtra(bundle,bundle);
startActivityForResult(intent,1);
}

});

返回rootView;

$ b public void showAlertDialog(Context context,String title,String message,Boolean status){
AlertDialog alertDialog = new AlertDialog.Builder(context).create();

//设置对话框标题
alertDialog.setTitle(title);

//设置对话框消息
alertDialog.setMessage(message);

//设置警告对话框图标
//alertDialog.setIcon((状态)?R.drawable.success:R.drawable.fail);

//设置OK按钮
alertDialog.setButton(OK,new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog,int which){
}
});

//显示提示信息
alertDialog.show();
}

@Override
public void onActivityResult(int requestCode,int resultCode,Intent data){
super.onActivityResult(requestCode,resultCode,data);
if(requestCode == 1){
if(resultCode == Activity.RESULT_OK){
Bundle b = data.getExtras();
if(b!= null){
ProdModel myobj =(ProdModel)b.getSerializable(Cart_Quantity); $(b)if(myobj!= null){
if(prodList!= null){
for(ProdModel P:prodList){
if(P.getEntity_id()。equals myobj.getEntity_id())){
P.setProductNumQuantity(myobj.getProductNumQuantity());


$ b Log.d(TAG,Product_Id:+ myobj.getEntity_id()
+,Product_Cart_Count:+ myobj.getProductNumQuantity( ));


} else if(resultCode == 0){
Log.d(TAG,RESULT CANCELLED);
}
}
adapter.notifyDataSetChanged();
字符串totalProductCart = spref.getString(Cart_Count_Tool,0);
Activity activity = getActivity();
if(activity instanceof TabActivity){
TabActivity myActivity =(TabActivity)activity;
工具栏工具栏=(工具栏)myActivity.findViewById(R.id.back_toolbar);
ImageView cart_imageview =(ImageView)toolbar.findViewById(R.id.cart_imageview);
cart_imageview.setImageDrawable(myActivity.buildCounterDrawable(
Integer.parseInt(totalProductCart)));
}
Log.d(TAG,RESULT NOTIFIED);
}

公共无效refreshData(字符串的productId,布尔isAddAsyncTaskComplete,
布尔isAddAsyncTaskLimitReached,布尔isDeleteAsyncTaskComplete){
adapter.setQuantityCount(产品数,的productId,isAddAsyncTaskComplete,
isAddAsyncTaskLimitReached,isDeleteAsyncTaskComplete);


TabActivity布局

 <?xml version =1.0encoding =utf-8?> 
< android.support.design.widget.CoordinatorLayout
xmlns:android =http://schemas.android.com/apk/res/android
xmlns:app =http ://schemas.android.com/apk/res-auto
android:layout_width =match_parent
android:layout_height =match_parent>

< android.support.design.widget.AppBarLayout
android:layout_width =match_parent
android:layout_height =wrap_content>

< android.support.design.widget.TabLayout
android:id =@ + id / tabs
android:layout_width =match_parent
android :layout_height =wrap_content
android:layout_below =@ + id / storeimage
android:textAlignment =center
android:elevation =2dp
android:minHeight =?attr / actionBarSize
app:tabMode =scrollable
app:tabTextColor =@ color / color_dark_blue
app:tabSelectedTextColor =@ color / color_orange/>
< /android.support.design.widget.AppBarLayout>

< android.support.v4.view.ViewPager
android:id =@ + id / viewpager
android:layout_width =match_parent
android :layout_height =match_parent
app:layout_behavior =@ string / appbar_scrolling_view_behavior/>
< /android.support.design.widget.CoordinatorLayout>

ListView

  xmlns:android =http://schemas.android.com/apk/res/android
android:layout_width =match_parent
android:layout_height = match_parent >

< ListView
android:id =@ + id / prodlist
android:layout_width =match_parent
android:layout_height =wrap_content/> ;

< / FrameLayout>


解决方案

$ c> Fragment 放入 setArguments()中。你的 Fragment 可以工作,但是当它试图保存它的实例状态时,它会溢出事务缓冲区。如果您的目标是Android 7.0(API 24或更高版本),则会引发 RuntimeException 。为了保持向后兼容性并且不破坏现有的应用程序,只有在您定位API 24或更高版本时才会使用新行为。如果您的目标是API< 24,事务缓冲区溢出异常被捕获并静静地忽略。这意味着您的数据将不会被永久保存,您可能(也可能不会)注意到。



您的代码已损坏。您不应将大量数据传递到 setArguments()中的 Fragment 。您可以将数据保存在 Activity 中。当 Fragment 想要访问数据时,它总是如此:

  //获取拥有的活动
MyActivity activity =(MyActivity)getActivity();
//从Activity获取数据
List< Data> data = activity.getData();

Activity 中,写一个 getData()方法,该方法返回对 Fragment 需要的任何数据的引用。

通过这种方式,数据保存在 Activity 中,并且 Fragment 可以随时访问它需要。


Exception

 05-12 15:42:45.791 11043-11043/ E/UncaughtException: java.lang.RuntimeException: android.os.TransactionTooLargeException: data parcel size 631792 bytes
                                                                       at android.app.ActivityThread$StopInfo.run(ActivityThread.java:3776)
                                                                       at android.os.Handler.handleCallback(Handler.java:751)
                                                                       at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                       at android.os.Looper.loop(Looper.java:154)
                                                                       at android.app.ActivityThread.main(ActivityThread.java:6123)
                                                                       at java.lang.reflect.Method.invoke(Native Method)
                                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
                                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)
                                                                    Caused by: android.os.TransactionTooLargeException: data parcel size 631792 bytes
                                                                       at android.os.BinderProxy.transactNative(Native Method)
                                                                       at android.os.BinderProxy.transact(Binder.java:615)
                                                                       at android.app.ActivityManagerProxy.activityStopped(ActivityManagerNative.java:3700)
                                                                       at android.app.ActivityThread$StopInfo.run(ActivityThread.java:3768)
                                                                       at android.os.Handler.handleCallback(Handler.java:751) 
                                                                       at android.os.Handler.dispatchMessage(Handler.java:95) 
                                                                       at android.os.Looper.loop(Looper.java:154) 
                                                                       at android.app.ActivityThread.main(ActivityThread.java:6123) 
                                                                       at java.lang.reflect.Method.invoke(Native Method) 
                                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867) 
                                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757) 
05-12 15:42:47.247 11043-11043/ E/AndroidRuntime: FATAL EXCEPTION: main
                                                                Process: , PID: 11043
                                                                java.lang.RuntimeException: android.os.TransactionTooLargeException: data parcel size 631792 bytes
                                                                    at android.app.ActivityThread$StopInfo.run(ActivityThread.java:3776)
                                                                    at android.os.Handler.handleCallback(Handler.java:751)
                                                                    at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                    at android.os.Looper.loop(Looper.java:154)
                                                                    at android.app.ActivityThread.main(ActivityThread.java:6123)
                                                                    at java.lang.reflect.Method.invoke(Native Method)
                                                                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
                                                                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)
                                                                 Caused by: android.os.TransactionTooLargeException: data parcel size 631792 bytes
                                                                    at android.os.BinderProxy.transactNative(Native Method)
                                                                    at android.os.BinderProxy.transact(Binder.java:615)
                                                                    at android.app.ActivityManagerProxy.activityStopped(ActivityManagerNative.java:3700)
                                                                    at android.app.ActivityThread$StopInfo.run(ActivityThread.java:3768)
                                                                    at android.os.Handler.handleCallback(Handler.java:751) 
                                                                    at android.os.Handler.dispatchMessage(Handler.java:95) 
                                                                    at android.os.Looper.loop(Looper.java:154) 
                                                                    at android.app.ActivityThread.main(ActivityThread.java:6123) 
                                                                    at java.lang.reflect.Method.invoke(Native Method) 
                                                                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867) 
                                                                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757) 

Fragment OnItemClick:-

 listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position,
                                long id) {

            Bundle bundle = new Bundle();
            ProdModel mProdModel = prodList.get(position);
            bundle.putSerializable("object", mProdModel);
            Intent intent = new Intent(getActivity(), DetailActivity.class);
            intent.putExtra("bundle", bundle);
            startActivityForResult(intent, 1);

        }

    });

In DetailActivity,

Bundle bundle = getIntent().getBundleExtra("bundle");
    if (bundle != null) {
        ProdModel model = (ProdModel) bundle.getSerializable("object");
    }

DetailActivity Manifest,

  <activity
        android:name="com.mass.mysample.DetailActivity"
        android:screenOrientation="portrait" />

Image Loading Using Picasso,

 Picasso.with(this).load(model.getImage())
             .placeholder(R.drawable.logo_without)
             .fit().into(productimage);

Model Class

public class ProdModel implements Serializable {
private String seller_id;
String name;
private String image;
private float price;
private float specialprice;
private String entity_id;
private String productNumQuantity;
private String storetitle;
private String description;
private String discount;
private String max_price;
private String store_name;
private String StoreUrl;

public String getProductNumQuantity() {
    return productNumQuantity;
}

public void setProductNumQuantity(String productNumQuantity) {
    this.productNumQuantity = productNumQuantity;
}

public String getDiscount() {
    return discount;
}

public void setDiscount(String discount) {
    this.discount = discount;
}

public String getMax_price() {
    return max_price;
}

public void setMax_price(String max_price) {
    this.max_price = max_price;
}

public String getStore_name() {
    return store_name;
}

public void setStore_name(String store_name) {
    this.store_name = store_name;
}

public String getStoreUrl() {
    return StoreUrl;
}

public void setStoreUrl(String storeUrl) {
    StoreUrl = storeUrl;
}

public String getStoretitle() {
    return storetitle;
}

public void setStoretitle(String storetitle) {
    this.storetitle = storetitle;
}

public String getSeller_id() {
    return seller_id;
}

public void setSeller_id(String seller_id) {
    this.seller_id = seller_id;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public String getImage() {
    return image;
}

public void setImage(String image) {
    this.image = image;
}

public String getEntity_id() {
    return entity_id;
}

public void setEntity_id(String entity_id) {
    this.entity_id = entity_id;
}

public String getDescription() {
    return description;
}

public void setDescription(String description) {
    this.description = description;
}

public float getPrice() {
    return price;
}

public void setPrice(float price) {
    this.price = price;
}

public float getSpecialPrice() {
    return specialprice;
}

public void setSpecialPrice(float specialprice) {
    this.specialprice = specialprice;
}

}

Data flow from TabActivity to fragment,

1.I have a TabActivity with ViewPager and Fragment. 
2.In Fragment, I have a ListView.
3.The Data to fragment is passed from view pager adapter by set arguments.

Solutions I tried

1.A POJO class that implements Serialization. 
2.I use Picasso to load the image from image URL. 
3.This exception is thrown when OnItemClick on ListView in fragment passes data to DetailActivity to show all passed data.
4.I get this exception after the DetailActivity load's image and other data then app suddenly crashes.
5.I pass data in Intent was all POJO Object with Id, Name, Image URL, Price etc.,

Note:- App Crash only in NOUGAT

Finally, The fix I implemented

changing the targetSdkVersion to 23 from 25

After changing, my application not crashing in Nougat too.

All I have to Know is this proper solution or is there any workaround.

Please Guide to the proper way.

Thanks in advance.

Fragment

public class ProdFragment extends Fragment {
ListView listview;
SharedPreferences spref;
Boolean isInternetPresent = false;
ConnectionDetector cd;

private String toBeDisplayed,CatID;
private static final String TAG = ProdFragment.class.getSimpleName();
String totalProductCart;
private ArrayList<Root_SubCatModel> subCatList;
private ArrayList<ProdModel> prodList;
ProdAdapter adapter;

public ProdFragment() {
    // Required empty public constructor
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    spref = getActivity().getSharedPreferences(getResources().getString(R.string.myPref),
            Context.MODE_PRIVATE);
    Bundle bundle = getArguments();
    if (bundle != null) {
        int tabPosition = bundle.getInt("Tab_Position");
        toBeDisplayed = bundle.getString("Tab_ToBeDisplayed");
        CatID = bundle.getString("CategoryId");
        subCatList = (ArrayList<Root_SubCatModel>) bundle.getSerializable("Tab_Data");
    }
}

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

    cd = new ConnectionDetector(getActivity());
    listview = (ListView) rootView.findViewById(R.id.prodlist);
    if (subCatList != null) {
        adapter = new ProdAdapter(getActivity(),
                CatID,
                toBeDisplayed,
                R.layout.list_product,
                subCatList,
                (ProductCartCountListener)getActivity());
        listview.setAdapter(adapter);
        adapter.notifyDataSetChanged();

        prodList = new ArrayList<>();
        for(int i = 0; i<subCatList.size();i++){
            if (subCatList.get(i).getProd() != null) {
                if(toBeDisplayed.equals("SubCategory")){
                    if (CatID.equals(subCatList.get(i).getCategory_id())) {
                        this.prodList = subCatList.get(i).getProd();
                    }
                }else if(toBeDisplayed.equals("Products")) {
                    this.prodList = subCatList.get(i).getProd();
                }
            }
        }

    }

    listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position,
                                long id) {

            Bundle bundle = new Bundle();
            bundle.putSerializable("object", prodList.get(position));
            Intent intent = new Intent(getActivity(), DetailActivity.class);
            intent.putExtra("bundle", bundle);
            startActivityForResult(intent,1);
        }

    });

    return rootView;
}

public void showAlertDialog(Context context, String title, String message, Boolean status) {
    AlertDialog alertDialog = new AlertDialog.Builder(context).create();

    // Setting Dialog Title
    alertDialog.setTitle(title);

    // Setting Dialog Message
    alertDialog.setMessage(message);

    // Setting alert dialog icon
    //alertDialog.setIcon((status) ? R.drawable.success : R.drawable.fail);

    // Setting OK Button
    alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
        }
    });

    // Showing Alert Message
    alertDialog.show();
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == 1) {
        if (resultCode == Activity.RESULT_OK) {
            Bundle b = data.getExtras();
            if (b != null) {
                ProdModel myobj = (ProdModel) b.getSerializable("Cart_Quantity");
                if (myobj != null) {
                    if (prodList != null) {
                        for (ProdModel P : prodList) {
                            if (P.getEntity_id().equals(myobj.getEntity_id())) {
                                P.setProductNumQuantity(myobj.getProductNumQuantity());
                            }
                        }
                    }
                    Log.d(TAG,"Product_Id : " + myobj.getEntity_id()
                            + ", Product_Cart_Count : " + myobj.getProductNumQuantity());
                }
            }
        } else if (resultCode == 0) {
            Log.d(TAG,"RESULT CANCELLED");
        }
    }
    adapter.notifyDataSetChanged();
    String totalProductCart = spref.getString("Cart_Count_Tool", "0");
    Activity activity = getActivity();
    if(activity instanceof TabActivity){
        TabActivity myActivity = (TabActivity) activity;
        Toolbar toolbar = (Toolbar) myActivity.findViewById(R.id.back_toolbar);
        ImageView cart_imageview = (ImageView) toolbar.findViewById(R.id.cart_imageview);
        cart_imageview.setImageDrawable(myActivity.buildCounterDrawable(
                Integer.parseInt(totalProductCart)));
    }
    Log.d(TAG,"RESULT NOTIFIED");
}

public void refreshData(String productId, boolean isAddAsyncTaskComplete,
                        boolean isAddAsyncTaskLimitReached, boolean isDeleteAsyncTaskComplete){
    adapter.setQuantityCount(prodList, productId, isAddAsyncTaskComplete,
            isAddAsyncTaskLimitReached, isDeleteAsyncTaskComplete);

}

TabActivity Layout

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/storeimage"
        android:textAlignment="center"
        android:elevation="2dp"
        android:minHeight="?attr/actionBarSize"
        app:tabMode="scrollable"
        app:tabTextColor="@color/color_dark_blue"
        app:tabSelectedTextColor="@color/color_orange"/>
</android.support.design.widget.AppBarLayout>

<android.support.v4.view.ViewPager
    android:id="@+id/viewpager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />
 </android.support.design.widget.CoordinatorLayout>

ListView

<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ListView
    android:id="@+id/prodlist"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

</FrameLayout>

解决方案

Your are passing too much data to your Fragment in setArguments(). Your Fragment will work, but when it tries to save its instance state it overflows the transaction buffer. This throws a RuntimeException if you target Android 7.0 (API 24 or higher). To preserve backwards compatibility and not break existing apps, the new behaviour is only used if you target API 24 or higher. If you target API < 24, the transaction buffer overflow exception is caught and silently ignored. This means that your data will not be persistently saved, which you may (or may not) notice.

Your code is broken. You should not pass large amounts of data to the Fragment in setArguments(). You can keep your data in your Activity. When the Fragment wants to access the data, it can always so something like this:

// Get the owning Activity
MyActivity activity = (MyActivity)getActivity();
// Get the data from the Activity
List<Data> data = activity.getData();

In your Activity, write a getData() method that returns a reference to whatever data the Fragment needs.

In this way, the data is held in the Activity and the Fragment can get access to it whenever it needs to.

这篇关于在牛轧糖中的TransactionTooLargeException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆