【问题标题】:Android broadcast attivity no historyAndroid 广播热度无历史记录
【发布时间】:2014-04-28 21:55:36
【问题描述】:

我遇到了由 BroadcastReceiver 启动的活动的问题。

我使用此活动覆盖默认锁屏,我希望该活动不从堆栈映射。

我尝试使用各种标志:FLAG_ACTIVITY_NO_HISTORY、FLAG_ACTIVITY_CLEAR_TOP、FLAG_ACTIVITY_CLEAR_TASK...但所有这些都不起作用。

Receiver.java

public class Receiver extends BroadcastReceiver  {

public void onReceive(Context context, Intent intent) {

    context.startService(new Intent(context, MyService.class));

    Intent intent = new Intent(context, AppActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    //intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
    //intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    //intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    context.startActivity(intent);
}

AndroidManifest.xml

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

<uses-sdk android:minSdkVersion="8" />

<application android:icon="@drawable/icon" android:label="@string/app_name">

    <activity android:name="com.app.AppActivity" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar.Fullscreen"  android:launchMode="singleTop" android:noHistory="true">

        <intent-filter >
            <!-- <action android:name="android.intent.action.MAIN" /> --> 
            <!-- <category android:name="android.intent.category.LAUNCHER" /> -->
        </intent-filter>

    </activity>


    <service android:name="com.app.MyService" android:noHistory="true">
    </service>

    <receiver android:name="receiver.Receiver" android:noHistory="true">     

        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />            
        </intent-filter>                        
    </receiver>
</application>

【问题讨论】:

    标签: android android-activity broadcastreceiver history


    【解决方案1】:

    您可以像这样修改活动的启动模式

    <activity
            android:name="com.example.test"
            android:configChanges="orientation|screenSize"
            android:launchMode="singleInstance"
             >
    </activity>
    

    或者你可以使用`android:launchMode="singleTask"'

    “singleTask”和“singleInstance”活动只能开始一个任务。它们始终位于活动堆栈的根部。

    它们的区别:

    “singleTask”和“singleInstance”模式也仅在一个方面彼此不同:“singleTask”活动允许其他活动成为其任务的一部分。它始终位于其任务的根部,但其他活动(必须是“标准”和“singleTop”活动)可以启动到该任务中。另一方面,“singleInstance”活动不允许其他活动成为其任务的一部分。

    如此处所述http://developer.android.com/guide/topics/manifest/activity-element.html#lmode

    【讨论】:

      猜你喜欢
      • 2014-06-10
      • 1970-01-01
      • 2013-05-04
      • 1970-01-01
      • 1970-01-01
      • 2011-11-14
      • 2013-05-21
      • 2011-02-04
      • 1970-01-01
      相关资源
      最近更新 更多