【问题标题】:How to solve foreclose problem in start up my application?如何解决启动我的应用程序的止赎问题?
【发布时间】:2010-12-18 21:51:42
【问题描述】:

我正在开发一个 android 应用程序,我希望在我打开设备时自动调用我的应用程序。所以我在应用程序的 manifest.xml 文件中使用了此权限<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />,我使用了服务、活动和注册广播接收器在 manifest.xml 文件中。但是我在何时启动我的设备时出现了排除错误。如何解决这个问题。 我的接收方代码如下 context.startActivity(new Intent(context,ServicesDemo.class));
//在myReceiver的mainfest.xml中

<receiver android:name=".MyReceiver">
 <intent-filter>
  <action android:name="android.intent.action.BOOT_COMPLETED" />
  <category android:name="android.intent.category.HOME" />  
 </intent-filter> </receiver>

我收到了这个异常java.lang.RuntimeException: Unable to start receiver com.servicedemo.MyReceiver: android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?

【问题讨论】:

  • @thanks cxOder,我发布了 logcat

标签: android


【解决方案1】:

我正在开发一个 android 应用程序,我希望在我打开设备时自动调用我的应用程序

用户通常会因一千个太阳的炽热激情而讨厌它。请将此设置为可配置并默认禁用。

另外,请记住,如果太多开发人员滥用此功能,核心 Android 团队可能会阻止您在启动时启动 Activity。

如何解决这个问题

按照错误消息告诉您的操作:将 FLAG_ACTIVITY_NEW_TASK 标志添加到您的 Intent

【讨论】:

    猜你喜欢
    • 2020-04-12
    • 2020-04-25
    • 2020-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-25
    • 2021-11-10
    相关资源
    最近更新 更多