proper way to use intent android studio garudapixel

GarudaPixel – Working in the many activities in the Android Studio can be easier if we are connecting each activity one-by-one. We can do that with the Intent function that Android Studio has provided for us.

But, how do we get started with that?

Here what we have, Intent is helping you to connect the activity with another activity in the different condition such as on event click, on a timer, or on a gesture. It depends on what we building for.

proper way to use intent android studio
https://dribbble.com/shots/5252062-Full-Screens-of-HQ-Redesign

Imagine that we have two different screen design that we want to connect them so that the user able to click to see the details of the information that our product has provided. We have to use an Intent to make that happens.

So, here is The proper way to use an Intent in Android Studio.

First, you have to create 2 different activity in the Android Studio, you can start with the empty activity to make it easier. Do not forget to make the text in each activity has a different string. So, you will see the different content of each activity.

After that, you can provide a button to make an event for the user, this event that we used is OnClickListener. You can see the source code below.

public class MainActivity extends AppCompatActivity {
    public static final String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    /** Called when the user taps the Send button */
    public void sendMessage(View view) {
        Intent intent = new Intent(this, DisplayMessageActivity.class);
        EditText editText = (EditText) findViewById(R.id.editText);
        String message = editText.getText().toString();
        intent.putExtra(EXTRA_MESSAGE, message);
        startActivity(intent);
    }
}

So, you create a new function that we called sendMessage, after that you are passing that function name in the XML of a button. It is pretty easy.

Oh, wait, I still do not understand.

The proper way to use an Intent in Android Studio

Please watch that video above, he is gonna teach you how the Intent works. Also, you will gonna learn how to make an animation on it.

You’ve come so far not for this only, you are still able to learn many things. So, that is why we suggest you to explore more around this blog and find what you need (not what you want). See you in the next time, Thank you.

3 COMMENTS

LEAVE A REPLY

Please enter your comment!
Please enter your name here