Android开放的对话活动,而无需打开主活动背后 [英] android open dialogue activity without opening main activity behind it
问题描述
我写一个程序,在收到短信提供了一个快速回复的对话框。
Im writing a program that offers a quick reply dialog upon receipt of an SMS.
不过,我却得到了意想不到的结果。当我receieve短信,相应的对话框活动出现无法显示正确的电话号码和邮件,但有一个背后的第二个活动是在我的程序默认活动(这是当我启动我的应用程序是什么打开)
However, I am getting an unexpected result. When I receieve an SMS, the appropriate dialog activity comes up displaying the correct phone number and message, however there is a second activity behind it that is the 'default' activity in my program (it is what opens when i launch my application)
我不希望本次活动上来。快速回复活动应该拿出自身在无论用户在做之前之上。
I do not want this second activity to come up. The quick reply activity should come up by itself over top of whatever the user was doing before.
在'飘'的活动:
public class quickReply extends Activity {
String mNumber, mMessage;
TextView mMainText;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mMainText = (TextView)findViewById(R.id.mainText);
try{
Intent i = getIntent();
Bundle extras = i.getExtras();
mNumber = extras.getString("theNumber");
mMessage = extras.getString("theMessage");
this.setTitle("Message From:" + mNumber);
mMainText.setText(mMessage);
} catch(Exception e) {
mMainText.setText(e.getMessage());
}
}
}
内的的onReceive的调用活动()
The call to the activity inside an onReceive()
Intent i = new Intent(context, quickReply.class);
i.putExtra("theNumber", mNumber);
i.putExtra("theMessage", mMessage);
i.setFlags(
Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
该清单:
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".quickReply"
android:label="@string/app_name"
android:theme="@android:style/Theme.Dialog"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".SmsReceiver">
<intent-filter>
<action android:name=
"android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
</application>
推荐答案
这样的作品,在活动定义清单中我发现的唯一方法:
the only way I have found that works, in your activity definition in manifest:
android:launchMode="singleInstance"
但你必须要重新启动您的主/默认行为一旦被驳回的对话。注意:您将失去从previous推出所有的状态,所以这是一个理想的解决方案少
but then you have to relaunch your main/default activity once the dialog is dismissed. NOTE: you will lose all state from the previous launch, so this is a less than ideal solution.
更新:
您也可以做到这一点:
Intent.FLAG_ACTIVITY_CLEAR_TASK
所以这里就是我所做的:
so here's what I did:
- 打开原来的/主要活动
- 从一个服务,使用上述(主变再见)启动对话框样式的活动。
-
当用户关闭对话框,再次用一个额外的意图(IS_BACK)是在的onCreate(处理),并调用启动主:
- open the original/main activity
- from a service, launch the dialog style activity using the above (main goes bye-bye).
when the user dismisses the dialog, start main again with an extra intent (IS_BACK) that is processed in onCreate() and calls:
moveTaskToBack(真);
moveTaskToBack(true);
这将保持对话下任务上顶部和在叠层的背面主
this will keep the task under the dialog on top and your main in the back of the stack.
这篇关于Android开放的对话活动,而无需打开主活动背后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!