Which way to start a new activity is better?

In my learning process at Android Development, I came across two different ways to start a new activity. And now I'm starting to wonder.

Both of them work great. However, I want to know whether it is better to use one of the options and why?

My first example (and the one that I like more so far):

Intent intent = new Intent(this, MainMenuActivity.class);
            this.startActivity(intent);

And the second:

startActivity(new Intent("com.example.MENUSCREEN"));

Where do I need to add android: name to my intent filter in manifest:

<activity
    android:name="com.example.MainMenuActivity"
    android:label="@string/app_name" 
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
    <intent-filter>
        <action android:name="com.example.MENUSCREEN" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

And I realized that it’s right, that the intention is similar to the fact that I intend to do something? "Intention" to do an action.

+4
source share
2 answers

Just to answer your question:

What is the best way to start a new business?

, , , , Intent . /.

:

Intent intent = new Intent(this, MainMenuActivity.class);
this.startActivity(intent);

"", , , , , - , , "" , .

, :

startActivity(new Intent("com.example.MENUSCREEN"));

"", , , "//", , .

, , , , , , .

, !

!

+8
Intent helpIntent = new Intent(this, HowToPlay.class);
this.startActivity(helpIntent);

HowToPlay.

startActivity(new Intent("com.example.MENUSCREEN"));

, . , , , , .

, , , -, , , (, -, , ).

+3

Source: https://habr.com/ru/post/1530131/


All Articles