Okay, so here is my problem. I'm working on an android app and learning android at the same time, so most of the times I get errors. Normaly I can fix them after researching a bit, but I'm getting stuck in this point.
I'm trying to make a back button for every Activity in my app, so I thought about making a "BackButton" class, so I can instanciate it every time I want to. Here is my BackButton code:
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.app.Activity;
public class BackButton extends Activity implements View.OnClickListener{
public static Button BackButton;
// Defining the button
public BackButton() {
BackButton = (Button) findViewById(R.id.bBack);
BackButton.setOnClickListener(this);
}
//To get the Button
public static Button getBackButton() {
return BackButton;
}
// OnClickListener
public void onClick(View v) {
try {
Class MainActivityClass = Class.forName("eu.lafarga.treballderecerca.MainActivity");
Intent MainActivityIntent = new Intent(BackButton.this, MainActivityClass);
startActivity(MainActivityIntent);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}finally {
// Save the things we've done.
}
}
}
So, how should I implement this in any activity? I'm doind something wrong? (Sure I'm lol)