I work in Eclipse. In general, there is a switch between the Activity by pressing the button, the necessary classes are created and everything else, a manifest is registered, as a result, we have Activation 1 with two buttons on Activation 2 and Activation 3 ... but when you click on any, it throws on Activation 2 (SecondActivity). Regardless of pressing button 1 or button 2, it opens the same window (SecondActivity). here is the code MainActivity.java
public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button swith = (Button)findViewById(R.id.button1); Button swith3 = (Button)findViewById(R.id.button3); swith.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Intent SecAct = new Intent(getApplicationContext(), SecondActivity.class); Intent SecAct2 = new Intent(getApplicationContext(), SecondActivity2.class); startActivity(SecAct); startActivity(SecAct2); } }); swith3.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent threActivity = new Intent(MainActivity.this, SecondActivity2.class); startActivity(threActivity); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } manifesto:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="ru.example.carcar" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="21" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name="SecondActivity" android:label="@string/app_name"/> <activity android:name="SecondActivity2" android:label="@string/app_name"/> </application> </manifest> Early z was delighted ((eclips does not issue errors, but the phone still has two buttons that open the same activation window ((... here again, can I copy something wrong?
public class MainActivity extends Activity {
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button swith = (Button)findViewById(R.id.button1); Button swith3 = (Button)findViewById(R.id.button3); swith.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent(MainActivity.this, SecondActivity.class)); } }); swith3.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent(MainActivity.this, SecondActivity2.class)); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } p \ s swears at newnew syntactic obesity expected therefore wrote new
startActivity(SecAct)andstartActivity(SecAct2)can runSecAct? - temq