开发者

How to start an activity

I have created two classes: Example1 and Example2, which extends activity. Example1 contains a UI of buttons, while Example2 contains UI of TextEdit. 开发者_如何学编程I want to call Example2 when a button is clicked, so this code is in an onclick method

Intent i = new Intent();
i.setClassName("com.a.ui", "com.a.ui.Example2");
startActivity(i);

So I am able to get the UI of Example2 successfully. What's an alternate way of calling intent?

Is there any alternate way to start an activity?


you can call like this:

startActivity(new Intent(com.a.ui.this, com.a.ui.Example2.class));


You can try this way.

  Intent i = new Intent(com.a.ui.this, com.a.ui.Example2.class);
  startActivity(i);


And remember to include the Activity in your Manifest.xml

e.g.

<activity android:name=".SampleActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜