public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Log.i("MainActivity", "---------------------------onCreate "); } @Override protected void onNewIntent(Intent intent) { Log.i("MainActivity", "---------------------------onNewIntent intent = "+intent); setIntent(intent); super.onNewIntent(intent); } }
<activity android:name="com.example.badupush.MainActivity" android:label="@string/app_name" android:launchMode="singleTask"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>
onCreate是用来创建一个activity的,但activity处于任务栈的顶端时,不会再次调用onCreate。
如果你想用这个顶端的activity去处理新的Intent,可以利用onNewIntent()
按home键返回时,再打开app,会调用onNewIntent()