I am writing a program that offers a quick response dialog when receiving SMS.
However, I get an unexpected result. When I receive an SMS message, the corresponding dialog action appears with the correct phone number and message displayed, however it is followed by the second action, which is the default activity in my program (this is what opens when my application starts)
I do not want this second action to appear. The quick response operation should occur on its own over what happened before.
Floating activity:
public class quickReply extends Activity { String mNumber, mMessage; TextView mMainText; @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()); } }
}
Activity call inside 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);
Manifesto:
<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>
android android-activity dialog
jwheels
source share