Mr.Alright---切换手势导航、屏幕大小后,App进程被莫名杀死?

问题:切换手势导航、屏幕大小后,App被莫名杀死

分析:

App本省是个手电筒应用,也没有多少代码,但是发现切换手势导航、屏幕大小后,任意操作都会导致手电筒自动关闭。

尝试1:开始以为是代码逻辑的问题,研究了半天逻辑没发现啥问题,不经意将发现App的进程被杀死了,,,What the fuck?  (O_O)?

为了确保不是逻辑的问题,我把所有的逻辑全都注释掉,只留了一个onCreate()里面加载了个布局文件,发现进程依然被杀死了,那么好了,肯定不是代码逻辑了,那问题可能出在AndroidManifest.xml里面

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.xxx.flashlight">

    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
    <uses-feature android:name="android.hardware.camera" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name">
        <activity
            android:name="com.xxx.flashlight.FlashlightActivity"
            android:resizeableActivity="false"
            android:theme="@android:style/Theme.DeviceDefault.NoActionBar"
            android:launchMode="singleInstance"
            android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

我把所有的都注释掉之后一条一条的添加,当添加到android:resizeableActivity="false"的时候,问题出现了,然后去掉这句就不会被杀死,那么问题肯定是这句了。

至于为什么添加这个会被杀死,目前还是没找到根本原因。但是我感觉这句不应该有问题的,因为这是google官方禁止分屏的方法,不管咋说问题是解决了,去掉之后就不会被杀死了,但是就是要适配一下分屏的布局,由于布局比较简单,我的做法是在代码里修改

// 没问题的文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.xxx.flashlight">

    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
    <uses-feature android:name="android.hardware.camera" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name">
        <activity
            android:name="com.xxx.flashlight.FlashlightActivity"
            android:resizeableActivity="false"
            android:theme="@android:style/Theme.DeviceDefault.NoActionBar"
            android:launchMode="singleInstance"
            android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>


//对应的activity中处理布局,isInMultiWindowMode表示处于分屏模式
@Override
public void onMultiWindowModeChanged(boolean isInMultiWindowMode, Configuration newConfig) {
        super.onMultiWindowModeChanged(isInMultiWindowMode, newConfig);
        if (isInMultiWindowMode) {
            mSOS_on.setScaleX(0.6f);
            mSOS_on.setScaleY(0.6f);
            mSOS_off.setScaleX(0.6f);
            mSOS_off.setScaleY(0.6f);
            mSOS_on.setTranslationY(40);
            mSOS_off.setTranslationY(40);
        }
    }

问题解决了,留下了个疑问,为什么禁止分屏android:resizeableActivity="false" App的进程会被杀死,我才疏学浅,实在搞不懂,哪位大佬看到了,还望能帮忙解惑,谢谢!

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值