Reputation: 62199
I'm a beginner in Android. Here I have this code:
public class GPS extends Activity implements OnClickListener
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
View getGPSButton=findViewById(R.id.get_GPS);
getGPSButton.setOnClickListener(this);
View aboutButton=findViewById(R.id.about_button);
aboutButton.setOnClickListener(this);
View exitButton=findViewById(R.id.exit_button);
exitButton.setOnClickListener(this);
}
public void onClick(View v)
{
switch (v.getId())
{
case R.id.get_GPS:
Intent i = new Intent (this,getGPS.class);
startActivity(i);
case R.id.about_button:
Intent j = new Intent(this, About.class);
startActivity(j);
break;
case R.id.exit_button:
System.exit(0);
finish();
break;
}
}
}
But getGPS class never starts. Whatever button I press I get About class activity on display. I know, that my error is in Intent parapeters.What should I write in Intent(...)? The getGPS function counts longitude&latitude via GPS and then opens Google Maps at that coordinates. Everything is OK in that class. The exit functions also doesn't work. Both System.exit(0) and finish() do NOT take any effect, it opens About class when I press exit_button.
Waiting for your advices.Thanks in advance.
Upvotes: 0
Views: 204
Reputation: 20041
//you missed the break
case R.id.get_GPS:
Intent i = new Intent (this,getGPS.class);
startActivity(i);
break;
//if its an button lets do this
Button getGPSButton=(Button)findViewById(R.id.get_GPS);
getGPSButton.setOnClickListener(this);
Button aboutButton=(Button)findViewById(R.id.about_button);
aboutButton.setOnClickListener(this);
Button exitButton=(Button)findViewById(R.id.exit_button);
exitButton.setOnClickListener(this);
Upvotes: 1