Caller's Intent and Recipient's Intent

The book says

Note that Activity.getIntent() always returns the Intent that started the activity. This is what you sent when calling startActivity(Intent).

Does it mean the Intent objects refer to the same object in memory or identical but not the same?

Upon testing, doing

// MainActivity.kt
val intent = CheatActivity.newIntent( ... )
Log.d(TAG, "${intent.hashCode}")
startActivityForResult(intent, REQUEST_CODE_CHEAT)

// CheatActivity.kt
override fun onCreate( ... ) {
  super.onCreate(savedInstanceState)
  Log.d(TAG, "${intent.hashCode}")
}

Prints two different hash codes.

2019-10-12 07:21:33.693 2574-2574/geoquizbnr4kv2 D/GeoQuiz4K.MainActivity: Intent: 15809291
2019-10-12 07:21:33.816 2574-2574/geoquizbnr4kv2 D/GeoQuiz4K.CheatActivity: Intent: 83885626

so either the ActivityManager is manipulating the object and they are the same OR the ActivityManager creates a copy.

Either way, any extras put on the intent will remain the same.

1 Like