当我收到一条短信时,我的应用程序应该显示一个活动两秒钟,但有时该活动不显示(进程仍在运行)而且我不知道为什么(可能是一些模拟器错误)。这是我的代码:
RomariosListener.java:
package com.romario.android.smslistener;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class RomariosListener extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Intent i = new Intent(context, RomariosSmsActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
RomariosSmsActivity.java
package com.romario.android.smslistener;
import com.romario.android.smslistener.R;
import android.app.Activity;
import android.os.Bundle;
public class RomariosSmsActivity extends Activity {
private Thread thread;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.romarios_sms_activity);
thread= new Thread(){
@Override
public void run(){
try {
synchronized(this){
wait(2000);
finish();
}
} catch(Exception e){
}
}
};
thread.start();
}
}
显现:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.romario.android.smslistener"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/ic_launcher" android:label="@string/app_name">
<receiver android:name=".RomariosListener">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
<activity android:name="com.romario.android.smslistener.RomariosSmsActivity" android:label="@string/RSA"></activity>
</application>
<uses-sdk android:minSdkVersion="5" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
</manifest>
请帮助我,对不起我的英语