【问题标题】:Android-Launching an application when tablet boot up is completedAndroid-平板电脑启动完成时启动应用程序
【发布时间】:2013-03-27 15:30:21
【问题描述】:

我使用的是 Android 3.2,我创建了我的 android 应用程序,它会在我的平板电脑启动完成后自动启动。

一切正常,除了应用程序开始自动运行(启动完成后)时 Activity 运行两次。

当我手动启动应用程序时不会出现此问题。

公共类 BootStartUpApp 扩展 BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
    Intent startUpApps = new Intent(context, StartMainActivity.class);
    startUpApps.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(startUpApps);
}

}

在清单文件中我添加了以下代码:

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

<receiver android:name="com.logica.eHealthBox.tab.activity.BootStartUpApp" >
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </receiver>

【问题讨论】:

  • 有什么代码可以给我们看吗?.. 非常感谢 BroadcastReceiver 部分。

标签: java android performance android-intent


【解决方案1】:

这是怎么做的:

public class BootReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
         Intent i = new Intent(context, TestReceiversActivity.class);
         i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
         context.startActivity(i);
       }
}

在清单中添加一个条目:

<receiver android:name=".BootReceiver" />

也有活动。

更多信息,请查看this link 和this link

【讨论】:

  • 在 post 中使用了相同的代码,它工作正常,但我的问题是在启动完成后启动应用程序时,活动是 Running Twice
猜你喜欢
  • 1970-01-01
  • 2021-05-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-06-23
相关资源
最近更新 更多