恢复

时间:2017-09-25 08:45:57

标签: android xamarin xamarin.android

显然我们的Xamarin原生应用程序有时会在Android使用一段时间后崩溃,但我还没有能够重现它。

在我们的选项卡式应用程序中膨胀其中一个片段时,似乎会导致崩溃。知道这可能是什么?报告仅适用于Android 7,但应用程序用户很少,因此可能是巧合。该应用程序的目标是Android 7.0,但之前当应用程序将目标框架设置为android 6.0时,错误是相同的(有几行不同)。一点点运气谷歌搜索。

更新11/17/2017:我已经尝试捕获异常(尝试阻止你在BuildingListFragment中看到的2行代码)并抛出我自己的代码,但它没有被捕获并且在Google Play中出现相同的异常控制台崩溃报告。这对我来说仍然是一个问题,我们将不胜感激。

android.runtime.JavaProxyThrowable: at AlarmKeeper.Droid.BuildingListFragment.OnCreateView (Android.Views.LayoutInflater inflater, Android.Views.ViewGroup container, Android.OS.Bundle savedInstanceState) [0x00028] in <8584c8930bb24ecaa4ab45fc24b599b6>:0
at Android.Support.V4.App.Fragment.n_OnCreateView_Landroid_view_LayoutInflater_Landroid_view_ViewGroup_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_inflater, System.IntPtr native_container, System.IntPtr native_savedInstanceState) [0x00020] in <1e89c43d3c7d48b5ba69bfc0b1bdf114>:0
at (wrapper dynamic-method) System.Object:fc5b2ba7-0fe0-4b23-b87c-c512566cc5f6 (intptr,intptr,intptr,intptr,intptr)
at md5446876e046c50288069676734a083198.BuildingListFragment.n_onCreateView (Native Method)
at md5446876e046c50288069676734a083198.BuildingListFragment.onCreateView (BuildingListFragment.java:30)
at android.support.v4.app.Fragment.performCreateView (Fragment.java:2248)
at android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManager.java:1340)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState (FragmentManager.java:1569)
at android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManager.java:1636)
at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated (FragmentManager.java:2977)
at android.support.v4.app.FragmentController.dispatchActivityCreated (FragmentController.java:192)
at android.support.v4.app.FragmentActivity.onStart (FragmentActivity.java:603)
at android.support.v7.app.AppCompatActivity.onStart (AppCompatActivity.java:178)
at android.app.Instrumentation.callActivityOnStart (Instrumentation.java:1256)
at android.app.Activity.performStart (Activity.java:6972)
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2937)
at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3045)
at android.app.ActivityThread.-wrap14 (ActivityThread.java)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1642)
at android.os.Handler.dispatchMessage (Handler.java:102)
at android.os.Looper.loop (Looper.java:154)
at android.app.ActivityThread.main (ActivityThread.java:6776)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1410)

片段类:

public class BuildingListFragment : Fragment
{
    ...

    public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        base.OnCreateView(inflater, container, savedInstanceState);
        var view = inflater.Inflate(Resource.Layout.BuildingListFragment, container, false);

        ...
    }
...
}

适配器:

public class TabAdapter : FragmentPagerAdapter, IconPagerAdapter
{
    private MainActivity _context;

    public TabAdapter (MainActivity context, FragmentManager p0) : base(p0)
    {
        _context = context;
    }

    public override Fragment GetItem(int position)
    {
        switch (position) {
        case 0:
            return new BuildingListFragment ();
        case 1:
            return AlarmListFragment.NewInstance("active");
        case 2:
            return AlarmListFragment.NewInstance("confirmed");
        case 3:
            return new ProfileFragment();
        }

        return null;
    }

    public override int Count
    {
        get{ return 4; }
    }

    ...
}

MainActivity:

    private TabAdapter _adapter;
    private ViewPager _viewPager;

    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);

        ...

            _viewPager = FindViewById<ViewPager>(Resource.Id.main_view_pager);
            _adapter = new TabAdapter(this, SupportFragmentManager);
            _viewPager.Adapter = _adapter;
            _viewPager.AddOnPageChangeListener(this);

            _tabLayout = FindViewById<TabLayout>(Resource.Id.main_tab_layout);
            TabLayoutHelper.SetupWithViewPager(_tabLayout, _viewPager);

            var activeItem = Intent.GetIntExtra(ArgActiveFragment, 0);
            if (activeItem != 0)
            {
                _viewPager.SetCurrentItem(activeItem, false);
            }

BuildingListFragment.axml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center"
    android:background="@color/background">
    <LinearLayout
        android:id="@+id/error_container"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:background="@color/red"
        android:gravity="center"
        android:visibility="gone">
        <TextView
            android:id="@+id/error_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@color/white"
            android:textSize="16dp" />
    </LinearLayout>
    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/building_list_refresh"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:minWidth="25px"
            android:minHeight="25px"
            android:clickable="true">
            <ListView
                android:id="@+id/building_list"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:paddingTop="15dp"
                android:clipToPadding="false"
                android:divider="@color/light_grey"
                android:dividerHeight="1dp" />
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textStyle="normal"
                android:textSize="15dp"
                android:gravity="center"
                android:text="@string/no_buildings_in_list"
                android:id="@+id/no_buildings_text"
                android:textColor="@color/grey"
                android:layout_gravity="center" />
        </FrameLayout>
    </android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout>

1 个答案:

答案 0 :(得分:0)

不知道您是否仍然对此有疑问,但是在遇到类似问题时我发现了该线程;启用“不保留活动”选项后,我无法崩溃,但我设法通过将“背景进程限制”选项设置为“最多1个进程”来解决了该问题。