手把手教你搭建android项目框架番外(二) 项目动态调试工具

在andriod项目开发过程中,我们时常有这样的需求,例如:动态切换域名,动态切换abtest,动态切换服务器配置项等,但是开发过程中总是让服务器配合修改或者每次都修改代码后运行就很麻烦,所以我们就有了一个开发需求,即app运行过程中进行动态配置。

那么我们怎么做好一些呢?

这里推荐单独开发一个develop页面调试工具,并配置单独的入口,如图所示:
Screenshot_20230829_211904_One UI Home.jpg

其中androidDemo为主项目入口,developer tools为调试页面入口。

接下来我们来简单配置一下如何能够达到文中的效果。

首先我们在src路径下创建debug文件夹,并创建DeveloperToolsAct,manifest.xml文件等,这样做的好处是只有debug模式才显示该入口。

Screenshot_20230829_211904_One UI Home.jpg

然后我们修改debug/AndroidManifest.xml文件,将DeveloperToolsAct配置成项目入口。

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

    <application tools:ignore="MissingApplicationIcon">
        <activity
            android:name="yz.l.fm.DeveloperToolsAct"
            android:clearTaskOnLaunch="true"
            android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
            android:excludeFromRecents="true"
            android:exported="true"
            android:finishOnTaskLaunch="true"
            android:label="developer tools"
            android:launchMode="singleTop"
            android:screenOrientation="portrait"
            android:taskAffinity=".developer"
            tools:ignore="LockedOrientationActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

此时,我们debug模式运行项目,发现程序已经有两个入口了,但是默认启动项可能是DeveloperToolsAct。

如果默认启动的Activity不是预期的,那么我们仅需要在想要默认启动的activity配置中添加Default即可,代码如下:

   <activity
            android:name="yz.l.fm.SplashAct"
            android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
            android:exported="true"
            android:launchMode="singleTask"
            android:screenOrientation="portrait"
            tools:ignore="LockedOrientationActivity">
            <intent-filter>
                <category android:name="android.intent.category.DEFAULT" /> <!--添加这一行即可-->
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

此时我们仅需要在DeveloperToolsAct中写相关的动态切换代码即可达到目的。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值