标签:android activity加载方式 activity加载方式 activity与task android task
public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout ll = new LinearLayout(this); ll.setOrientation(LinearLayout.VERTICAL); this.setContentView(ll); TextView tv = new TextView(this); tv.setText("Activity为: " + this.toString() + "\n" + ", Task ID 为:" + this.getTaskId()); Button button = new Button(this); button.setText("启动Activity"); ll.addView(tv); ll.addView(button); button.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(MainActivity.this, MainActivity.class); startActivity(intent); } } ); } }
public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout ll = new LinearLayout(this); ll.setOrientation(LinearLayout.VERTICAL); this.setContentView(ll); TextView tv = new TextView(this); tv.setText("Activity为: " + this.toString() + "\n" + ", Task ID 为:" + this.getTaskId()); Button button = new Button(this); button.setText("启动Activity"); ll.addView(tv); ll.addView(button); button.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(MainActivity.this, SecondActivity.class); startActivity(intent); } } ); } } public class SecondActivity extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout ll = new LinearLayout(this); ll.setOrientation(LinearLayout.VERTICAL); this.setContentView(ll); TextView tv = new TextView(this); tv.setText("Activity为: " + this.toString() + "\n" + ", Task ID 为:" + this.getTaskId()); Button button = new Button(this); button.setText("启动Activity"); ll.addView(tv); ll.addView(button); button.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(SecondActivity.this,MainActivity.class); startActivity(intent); } } ); } }
public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout ll = new LinearLayout(this); ll.setOrientation(LinearLayout.VERTICAL); this.setContentView(ll); TextView tv = new TextView(this); tv.setText("Activity为: " + this.toString() + "\n" + ", Task ID 为:" + this.getTaskId()); Button button = new Button(this); button.setText("启动Activity"); ll.addView(tv); ll.addView(button); button.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(MainActivity.this, SecondActivity.class); startActivity(intent); } } ); } } public class SecondActivity extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout ll = new LinearLayout(this); ll.setOrientation(LinearLayout.VERTICAL); this.setContentView(ll); TextView tv = new TextView(this); tv.setText("Activity为: " + this.toString() + "\n" + ", Task ID 为:" + this.getTaskId()); Button button = new Button(this); button.setText("启动Activity"); ll.addView(tv); ll.addView(button); button.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(); intent.setAction("org.crazyit.intent.action.CRAZYIT_ACTION"); startActivity(intent); } } ); } } <activity android:name="com.example.dada.testapplication.SecondActivity" android:launchMode="singleInstance" android:exported="true" android:label="@string/title_activity_second" > <intent-filter> <action android:name="org.crazyit.intent.action.CRAZYIT_ACTION" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity>
标签:android activity加载方式 activity加载方式 activity与task android task
原文地址:http://blog.csdn.net/jing_unique_da/article/details/43530493