gpt4 book ai didi

java - 调试在启动时运行的应用程序

转载 作者:行者123 更新时间:2023-11-29 08:31:29 24 4
gpt4 key购买 nike

我正在使用 Android Studio。

我为接收 android.intent.action.BOOT_COMPLETED 的应用程序添加了 BroadcastReceiver,接收器仅显示 Toast 以供测试。问题是我在 Android 启动后收到“App has stopped”消息。

我的第一个问题是:有没有办法在启动时自行调试并查看问题出在哪里?因为我在 Android Studio 中看不到任何涉及该问题的日志。

我的第二个问题与问题本身有关。这是代码:XML:

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

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name="MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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

<receiver
android:name=".AutoStartReceiver"
android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>

</application>

</manifest>

Java:广播接收器

public class AutoStartReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "loaded", Toast.LENGTH_LONG).show();
throw new UnsupportedOperationException("Not yet implemented");
}
}

第三个问题是:是否可以在接收器中做一些繁重的工作(读取一些文件并设置AlarmManager)而不是创建服务?因为从 API 26 开始,Android 对服务施加了很多限制。

谢谢

最佳答案

对于调试部分,我使用了这个(在终端中,当模拟器打开时):

adb shell am set-debug-app -w --persistent <your.app.package> 

开始调试,然后当应用程序在模拟器上提示时单击将调试器附加到 android 进程enter image description here

要禁用此功能:

adb shell am clear-debug-app <your.app.package>

在这里找到答案:https://medium.com/@elye.project/debug-app-deeplink-at-launch-time-bdb2cf04a9e6

关于java - 调试在启动时运行的应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47759624/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com