Somk
Somk

Reputation: 12047

Android New Intent New Screen

I am still not completely sure of this opening a new screen with a new intent. I have two problems. 1 is getting it to work and the second is more theory.

Firstly I have two packages com.quiz.max and com.reason.max both have activities names accordingly eg Quiz and Reason respectively. Here is the on click code I am trying to execute at the moment in quiz to go to reason.

        Intent intent = new Intent();
        intent.setClassName("com.reason.max", "com.reason.max.Reason");
        this.startActivityForResult(intent, requestCode);

Secondly I heard if I start this intent then everytime i click the button a new intent is created. Does this mean if the user goes to reason page and navigates back and clicks the button again they actually create a new intent instead of going back to the already active one. Thus dozens could be opened via this method. Therefore should I close each reason intent once navigated back or is this a redundant point?

Max

Upvotes: 0

Views: 1479

Answers (1)

Cheryl Simon
Cheryl Simon

Reputation: 46844

I think you want

Intent intent = new Intent(this, Reason.class);
startActivityForResult(intent, requestCode);

Secondly, you don't "start an intent". You use an intent to ask an Activity to start, in this case the Reason activity. And yes, the default behavior is to start a new instance of the activity each time it is requested.

You can alter this behavior with the launchMode.

Make sure you read and understand the Activity lifecycle. You don't need to worry about too many Activities in existence, Android will handle that for you, but you should properly save state and clean up connections in the appropriate lifecycle methods.

Upvotes: 2

Related Questions