这是我的清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.stopcall.app" >
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".activities.ItemDetailActivity"
android:label="@string/app_name" >
</activity>
<activity
android:name=".activities.PopupActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.Translucent.NoTitleBar">
</activity>
<activity
android:name=".activities.MainActivity"
android:label="@string/title_activity_main"
android:theme="@android:style/Theme.NoDisplay">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="com.example.stopcall.app.OutgoingCallReceiver" >
<!--<intent-filter>-->
<!--<action android:name="android.intent.action.CALL_BUTTON" />-->
<!--<category android:name="android.intent.category.DEFAULT" />-->
<!--</intent-filter>-->
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</intent-filter>
</receiver>
</application>
</manifest>
我开始申请。显示ItemDetailActivity
。
然后我暂停它(让它隐藏在任务堆栈中)。
我使用的触发器会触发PopupActivity
(半透明)和PopupFragment
。
我想只看到片段,在创建时浮动在拨号器上。
这就是我添加android:theme="@android:style/Theme.Translucent.NoTitleBar">
然而,当显示片段时,ItemDetailActivity
突然从堆栈中出现并显示为背景。
我该如何避免这种情况?意思是只有片段会在拨号器的顶部被看到触发它吗?
修改
正如我所提到的。该片段显示了它的活动,它只是透明的。问题是我的应用程序的另一个不相关的活动突然出现在任务堆栈中。
我的最终目标是在拨号器上显示一个弹出窗口。可以吗?
修改
我的接收器使用弹出片段启动新的透明活动。
@Override
protected void handleReceive(Context context, Intent intent) {
..
Intent i = new Intent(context, PopupActivity.class);
i.putExtra(Constants.DIALED_PHONE, phoneDal.getItem(phoneNumber));
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
setResultData(null);
然而弹出窗口显示透明活动,并且显示先前显示的兄弟活动。
答案 0 :(得分:1)
我认为你的问题是显示透明活动会使其他活动可见。这是因为这些活动在同一个任务堆栈中。
您应该尝试使用标记FLAG_ACTIVITY_CLEAR_TASK
或FLAG_ACTIVITY_NEW_TASK
/**
* If set, this activity will become the start of a new task on this
* history stack. A task (from the activity that started it to the
* next task activity) defines an atomic group of activities that the
* user can move to. Tasks can be moved to the foreground and background;
* all of the activities inside of a particular task always remain in
* the same order. See
* <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back
* Stack</a> for more information about tasks.
*
* <p>This flag is generally used by activities that want
* to present a "launcher" style behavior: they give the user a list of
* separate things that can be done, which otherwise run completely
* independently of the activity launching them.
*
* <p>When using this flag, if a task is already running for the activity
* you are now starting, then a new activity will not be started; instead,
* the current task will simply be brought to the front of the screen with
* the state it was last in. See {@link #FLAG_ACTIVITY_MULTIPLE_TASK} for a flag
* to disable this behavior.
*
* <p>This flag can not be used when the caller is requesting a result from
* the activity being launched.
*/
public static final int FLAG_ACTIVITY_NEW_TASK = 0x10000000;
/**
* If set in an Intent passed to {@link Context#startActivity Context.startActivity()},
* this flag will cause any existing task that would be associated with the
* activity to be cleared before the activity is started. That is, the activity
* becomes the new root of an otherwise empty task, and any old activities
* are finished. This can only be used in conjunction with {@link #FLAG_ACTIVITY_NEW_TASK}.
*/
public static final int FLAG_ACTIVITY_CLEAR_TASK = 0X00008000;
如果您想在手机应用上显示您的用户界面。
执行此操作的最佳方法是使用浮动窗口。这也是一种非常流行的技术,用于在其他应用程序之上显示GUI等对话框。您可以通过Google获取更多信息,以下是一些基本操作。
mWindowManager = (WindowManager)getSystemService(WINDOW_SERVICE);
mWindowManager.addView(mView, mParams); //add the floating view
mWindowManager.updateViewLayout(mView, mParams); //update layout parameters (size/position)
mWindowManager.removeView(mView); //remote the floating view