我正在编写我的第一个 Android 应用程序,并希望获得良好的编码实践。我有一个包含以下内容的 Activity :
Button btn = (Button)findViewById(R.id.btnPressMe);
btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent(Main.this, SecondScreen.class));
}
});
或
startActivity(new Intent("net.mysite.MediaPlayer.CLEARSCREEN"));
AndroidManifest.xml:
<activity
android:name=".landingpage"
android:label="@string/app_name" >
<intent-filter>
<action android:name="net.mysite.MediaPlayer.CLEARSCREEN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
最佳答案
描述的第一种方式最好在您的应用程序中使用,另一种方式用于其他应用程序调用您的 Activity 。
关于Android - 使用 Activity 的最佳方式是什么(最佳实践),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8864025/