我正在编写一个程序,当收到短信时可以提供快速回复对话框。
清单文件(Manifest):
但是,我得到了一个意外的结果。当我接收到短信时,适当的对话框活动会显示正确的电话号码和消息,但是在其后面还有第二个活动,这是我的程序中的“默认”活动(当我启动应用程序时它就会打开)。
我不希望出现第二个活动。快速回复活动应该单独出现在用户之前所做的任何事情上方。
这个“悬浮”的活动:
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()中调用活动
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);
清单文件(Manifest):
<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>