Relevant Code Snippet:
public class MyPreference extends Preference {
public MyPreference(Context context, AttributeSet attrs) {
super(context, attrs);
this.ctx = context;
this.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
Toast.makeText(ctx, "Preference has been clicked", Toast.LENGTH_LONG).show();
return true;
}
});
}
}
Now I want to do some processing(basically call finish()) once the onPreferenceClick handler returns me true.
Pointers?
EDIT
Added finish() inside the onClick but its not working. No error. Just a Toast and nothing else. My intention is to close the app once MyPreferenceis clicked
public boolean onPreferenceClick(Preference preference) {
Toast.makeText(ctx, "Preference has been clicked", Toast.LENGTH_LONG).show();
MainPreferenceActivity mainPref = new MainPreferenceActivity();
mainPref.finish();
return true;
}
Probably I am doing it incorrectly. Creating a newInstance of MainActivity will not kill the parent MainActivity I guess, right? I am new to Java n android. Sorry 🙁 !
Try Debugging the Code with Eclipse where you can set the Debugging Points and can check the flow and also different values in every variable. Even you can check step by step debugging.
Moving to next Debug point with f8 and Debugging with step by step is with f6.
This can be helpful top check every where in the code.