public class MainActivity extends AppCompatActivity {
private Activity mActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mActivity = MainActivity.this;
Button button = (Button) findViewById(R.id.restart_button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
restartActivity(mActivity);
}
});
}
}
public static void restartActivity(Activity activity) {
if (Build.VERSION.SDK_INT >= 11) {
activity.recreate();
} else {
activity.finish();
activity.startActivity(activity.getIntent());
}
}