例外
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)
片段点击:-
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);
}
});
在活动中,
Bundle bundle = getIntent().getBundleExtra("bundle");
if (bundle != null) {
ProdModel model = (ProdModel) bundle.getSerializable("object");
}
详细活动清单,
<activity
android:name="com.mass.mysample.DetailActivity"
android:screenOrientation="portrait" />
图像加载使用毕加索,
Picasso.with(this).load(model.getImage())
.placeholder(R.drawable.logo_without)
.fit().into(productimage);
模型类
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;
}
}
从活动到片段的数据流,
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.
我尝试过的解决方案
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.,
注意:-应用程序崩溃只在NOUGAT
最后,我实现了修复
将targetSdkVersion从25更改为23
更改后,我的应用程序在牛轧糖也不会崩溃。
我所要知道的就是这个合适的解决方案,或者有什么变通办法。
请引导到正确的方式。
提前谢谢。
碎片
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);
}
选项卡布局
<?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>
列表视图
<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>
当值太大而无法放入事务缓冲区时,将抛出Doc This异常。对于一个大型项目来说,这可能是一个复杂的问题,在这个项目中,您可以通过在不同的地方发送Intent来调用几个操作。
您的示例演示了这个问题,即使是单个对象。你应该改变你的转移行为。通过修剪对象,只包含重要信息。意图额外数据应该只有轻量级的信息!
在您的示例中,您有一个字段,它可能会产生此问题。可能您使用的是Base64编码图像。消息文本例外,仅适用于Android 23。检查一下文件。
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
Android7.0(Nogat)包括各种系统和API行为更改。关于TransactionTooLarge异常:
在Android 7.0中,许多平台API现在已经开始检查在绑定器事务中发送的大型有效负载,并且系统现在将TransactionToolArgeException作为RuntimeException重新刷新,而不是静默地记录或抑制它们。一个常见的例子是在活动中存储太多数据。onSaveInstanceState(),这将导致ActivityThread。StopInfo在应用程序针对Android 7.0时引发RuntimeException。
可能的解决办法:1。将所需对象保存在全局缓存中,并仅传递DetailsActivity键以检索该对象。
在setArguments()中,您将太多的数据传递给您的碎片。您的片段
将正常工作,但是当它试图保存其实例状态时,它会溢出事务缓冲区。如果您的目标是Android 7.0(API 24或更高版本),则会抛出一个RuntimeExc0019
。为了保持向后的兼容性,并且不破坏现有的应用程序,只有在以API 24或更高版本为目标时才会使用新行为。如果你瞄准API
你的代码坏了。您不应该将大量数据传递给setArguments()
中的碎片
。您可以将数据保存在活动中。当碎片想要访问数据时,它总是可以这样:
// Get the owning Activity
MyActivity activity = (MyActivity)getActivity();
// Get the data from the Activity
List<Data> data = activity.getData();
在活动
中,编写一个getData()
方法,返回对片段
需要的任何数据的引用。
通过这种方式,数据保存在活动中
,而片段
可以随时访问它。
我尝试了太多的选项/博客/脚本来安装GooglePlay for Emulator(通过Android Studio运行),但都没有成功。我看到了很多不同的错误 失败[安装失败\u更新不兼容] 评论-为什么在Emulator上安装GooglePlay如此困难,有人能提供与Marshmallow/Noughat一起使用的步骤或GAPP吗。或者为什么谷歌不提供标准步骤来为模拟器安装GApps! 以下是
我的应用程序在之前的Android版本上运行完美,在实际设备上从4.0测试到6.0.1。工作室仿真牛轧糖7.0和7.1没问题。然而,当我让我的朋友在他运行7.0的设备上测试APK时,这在几秒钟内就发生了: 崩溃通知 我没有访问该设备的权限(他住得很远),并且我无法在网上找到该特定错误的任何相关信息。原因可能是什么?
在清单文件中:
我正在使用reverfit进行api调用,我从服务器得到了几乎不到30KB大小的JSON响应。当JSON将响应解析为一个复杂对象时,它会抛出这个错误。 如果我尝试将响应存储在对象类中,然后通过LinkedHashMap获取值,我就能够获取数据。但是,这将是一个繁琐的过程。 有谁能帮我弄清楚这里的问题是什么,以及如何找到解决办法吗? 根据我的研究,这种情况只发生在版本>=牛轧糖的android设备上
我尝试在我的应用程序中构建导航抽屉,导航抽屉在之前版本的牛轧糖中运行良好,但在牛轧糖中,导航抽屉不会出现在状态栏上。我尝试了很多解决方案,但没有在牛轧糖中发挥作用,请帮助!! 这是我的主要活动。xml文件: 我的styles.xml: 和样式(v21). xml 这是我当前的导航抽屉,我想放在状态栏上。