I intercept sms messages with some information in them. Then in my SmsListener I create a notification to display in the status bar. Then, when the user clicks on the notification, I want
- Bring MainActivity to the forefront (if such an activity has not yet been created, it must be created)
- Send him data from sms
- Make some ui changes based on this data in this MainActivity
My activity is defined as
<activity
android:name=".MainActivity"
android:screenOrientation="sensor"
android:label="@string/app_name"
android:launchMode="singleTask"/>
Activity starts as
Intent i = new Intent();
i.setClass(context, MainActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
Also in my work I have an overridden onNewActivity method
@Override
public void onNewIntent(Intent intent){
super.onNewIntent(intent);
processDataFromBroadcast(intent);
}
It works fine if MainActivity already exists, but if MainActivity does not exist, it starts, however onNewIntent was not called
processDataFromBroadcast onCreate: processDataFromBroadcast(getIntent()).
.
, MainActivity , , onCreate, onNewIntent, processDataFromBroadcast , , MainActivity , - , .
.