onNewIntent

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zsp_android_com/article/details/85339783

说明

Activity通Intent传数据时Activity未启则于该刚启Activity通getIntent()可获。将启Activity已存时通getIntent()获为已存Activity原始Intent。换句话说Intent数据没更新致于将启Activity获Intent为旧数据。每获Intent新数据则需onNewIntent(Intent intent)调setIntent(intent)设所传最新Intent。

源码

/**
 * Change the intent returned by {@link #getIntent}.  This holds a
 * reference to the given intent; it does not copy it.  Often used in
 * conjunction with {@link #onNewIntent}.
 *
 * @param newIntent The new Intent object to return from getIntent
 *
 * @see #getIntent
 * @see #onNewIntent
 */
public void setIntent(Intent newIntent) {
    mIntent = newIntent;
}
/** Return the intent that started this activity. */
public Intent getIntent() {
    return mIntent;
}

使用

@Override
protected void onNewIntent(Intent intent) {
	super.onNewIntent(intent);
    // 通Intent获数据    
}
setIntent(intent);
getIntent();        

猜你喜欢

转载自blog.csdn.net/zsp_android_com/article/details/85339783