Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Switch between activities
    primarykey
    data
    text
    <p>what i'm trying to do is a home screen that stays for 5 seconds and goes to activity1.When i click a button in activity1 leads me to activity2.I've tried many times to click the button but no switching happens. homescreen (5 seconds)=Main_Activity Activity1=selectpets.java Activity2=fishtank.java</p> <p>onclick listener seems the problem i don't know what's wrong with it </p> <pre><code> Main Activity Code package com.set.petshome; import android.os.Bundle; import android.os.Handler; import android.app.Activity; import android.content.Intent; import android.view.Menu; import android.view.View; import android.widget.Button; public class MainActivity extends Activity { Button fButton; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //Delay Code after 5 seconds new Handler().postDelayed(new Runnable() { @Override public void run() { setContentView(R.layout.selectscreen); //where &lt;next&gt; is you target activity :) } }, 5000); } //Delay End @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; } } </code></pre> <p>Now the Selectpets Code</p> <pre><code>package com.set.petshome; import android.app.Activity; import android.content.*; import android.os.Bundle; import android.view.*; import android.widget.Button; public class SelectPetsScreen extends Activity { Button fButton; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.selectscreen); //Button Fishtank Listener Start fButton = (Button) findViewById(R.id.button1); //Listening to button event fButton.setOnClickListener(new View.OnClickListener() { public void onClick(View arg0) { //Starting a new Intent Intent nextScreen = new Intent(getApplicationContext(), fishtank.class); startActivity(nextScreen); } }); //Button Fishtank Listener End } } </code></pre> <p>Fishtank class code</p> <pre><code>package com.set.petshome; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.Menu; import android.view.View; import android.widget.Button; public class fishtank extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.ftank); } } </code></pre> <p>by the way no errors in the application just no switching after clicking<br> thank you very much</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload