I have a problem when I logout using the Facebook API. Apart from the button to log in and out, I have another button that allows access to other activity, what happens is that when I logout I want to disappear the button that gives me access to the other activity and I can not do it, I have tried many combinations with all methods of the main activity and nothing works
Any suggestions?
Get a reference to the Facebook Login Button and set a click listener on it and when click is registered, logout using LoginManager instance and make all your logout procedure ( such as clearing stored access token, clearing cache, etc.) and then make visibility of the other button View.GONE
Eg:
LoginButton mBtnFbLogin = (LoginButton) findViewById(R.id.fb_login_button);
Button otherButton = (Button) findViewById(R.id.other_button)
Now set click listener on it.
mBtnFbLogin.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
LoginManager.getInstance().logOut();
// Make your logout procedure
...
otherButton.setVisibility(View.GONE);
}
});
Thank your for your answer, the solution works. Finally I do this:
#Override
protected void onResume() {
super.onResume();
AppEventsLogger.activateApp(this);
if (AccessToken.getCurrentAccessToken() != null && com.facebook.Profile.getCurrentProfile() != null) {
boton_volver.setVisibility(View.VISIBLE);
boton_volver.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent;
intent = new Intent(v.getContext(), EventosActivity.class);
startActivity(intent);
}
});
} else {
boton_volver.setVisibility(View.INVISIBLE);
}
}
Related
I have a main_activity in which by pressing a button I launch a form to be completed:
popup= getLayoutInflater().inflate(R.layout.pop_up, null);
signup = new SignUp(popup);
register = (Button) findViewById(R.id.sign_up);
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(MyLocalBartender.this);
alertBuilder.setView(popup);
final AlertDialog dialog = alertBuilder.create();
register.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
dialog.dismiss();
dialog.show();
}
});
By what you can see I'm using a second activity class (SignUp) to manage the form and not the root class from which it was launched (main_activity).
In this new class I set all the click listeners etc to verify the inputs through a third class that implements an OnClickListener.
Everything works fine until this point. But now I want to test the page/activity called HomePage in which the user should land to if the form is filled.
So what I don know is I remove the click listener from the previous handler and I create an anonymous one to simply open the new activity on register button pressed:
// signup_registerButton.setOnClickListener(new SignupListener(signup_emailField,signup_passwordField1,
// signup_passwordField2, signup_textTemp,signup_organiserRadio, signup_staffRadio,signup_alertMessage));
////*************************TEST******************* START
signup_registerButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent menu = new Intent(getApplicationContext(), HomePage.class);
startActivity(menu);
}
});
////*************************TEST******************* END
but this returns a NullPointerException.
I've tried to launch the HomePage.class from the main_activity directly and it works and also I've tried to launch the main activity from this REGISTER button, which didn't work, so this tells me that the problem it is somewhere here.
You need to pass an Activity Context to the Intent constructor. Activities context and Applications context are not the same. Activities context hold much more inforamtions.
In your case you can do like this:
signup_registerButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent menu = new Intent(yourActivity, HomePage.class);
startActivity(menu);
}
});
where yourActivity is your activity instance. You can pass it as variable or access it via main_activity.this from inner classes (Listeners) on anywhere inside your class.
I am trying to implement simple back button on activity to go to previous activity, but some weird behavior is happening when I am calling method finish() - the problem is I have to press back button TWO times? Why is this happening? In the back method i have only finish(). What is the other way to go to previous saved activity without instantiate a completely new Intent?
public void back1 (View view){
this.finish();
}
This is second try with the same result:
ImageButton buttonback = (ImageButton) findViewById(R.id.imageButton6);
buttonback.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
onBackPressed();
}
});
You are most likely starting the activity twice.
When pressing back you are finishing one, and the other one is coming forward. Check your onCreate and onResume for anything that may be using intents or starting any activity
#Override
public void onBackPressed() {
super.onBackPressed();
}
add that to your code the super call closes the activity no need to call finish()
If you just want the devices back button to function, you dont need to override the onBackPressed method in Activity.
If you want to place a custom button in view and set back action to that button, then you need to write button clicklistener to the same
backbutton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
finish();
}
});
I am making a log-in system on Android. And I want the register Button to be unclickable when it has been clicked. I am using this code:
final Button register = (Button) findViewById(R.id.register);
register.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
register.setEnabled(false);
Intent register = new Intent(getApplicationContext(), register.class);
startActivity(register);
}
});
This is working great, but I want the Button to remain unclickable even when the application or phone has been restarted. Does anyone know a way to make the Button unclickable permanently even when the application has been shut down?
As I already said in the comments section something like this may work:
public class MyActivity extends Activity {
private static final String KEY_IS_BUTTON_CLICKABLE = "key_clickable";
#Override
public void onCreate(Bundle savedInstanceState) {
...
final Button register = (Button) findViewById(R.id.register);
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
boolean isClickable = sharedPreferences.getBoolean(KEY_IS_BUTTON_CLICKABLE, true);
register.setEnabled(isClickable);
if(isClickable) {
register.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
register.setEnabled(false);
PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit()
.putBoolean(KEY_IS_BUTTON_CLICKABLE, false);
Intent register = new Intent(getApplicationContext(), register.class);
startActivity(register);
}
});
}
}
...
}
In this case you could take a pessimistic approach and disable the button in the layout (by default) with android:clickable="false" and enable it in the condition where registration is required.
I'm creating a dialog box and using the (this) isnt working. Up until now its just been a button calling a dialogbox but now the button within the called dialogbox needs to call another dialog. The Dialog dialogdelcon is the one with problem.
Here is the code:
case R.id.delappt:
//rmvall();
final Dialog dialogdelsel = new Dialog(this);
dialogdelsel.setContentView(R.layout.delsel);
dialogdelsel.setTitle("What would you like to do?");
dialogdelsel.setCancelable(true);
Button btndelsel = (Button) dialogdelsel.findViewById(R.id.btndelsel);
btndelsel.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// delete selected code here.
}
});
Button btndelall = (Button) dialogdelsel.findViewById(R.id.btndelall);
btndelall.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// delete all code here.
final Dialog dialogdelcon = new Dialog();
dialogdelcon.setContentView(R.layout.delcon);
dialogdelcon.setTitle("Deletion Confirmation");
dialogdelcon.setCancelable(true);
Button buttoncnclok = (Button) dialogdelcon.findViewById(R.id.btndelcon);
buttoncnclok.setOnClickListener(new OnClickListener() {
// on click for cancel button
#Override
public void onClick(View v) {
dialogdelcon.dismiss();
}
});
dialogdelcon.show();
}
});
dialogdelsel.show();
break;
getApplicationContext() or use YourActictyName.this Because this refers the button click listner ,not your class Object
If this code is in the onCreate() method, or similiar, add getApplicationContext() instead of this and you should be fine. That's because this in a Button-context will refer to the button environment.
To improve the isolation between the two dialogs, it would be best to call showDialog(R.id.delapptcon) from the onClick handler. Then load the new dialog in the onCreateDialog of your activity. In this way, you can create more reusable dialogs and avoid the scoping issue you have now.
So my question is simple if I use the WebView.destroy() in my app can I restore WebView to it's original state when the app was first initialize with out closing my app and opening it again? and how can I do this? I just want to be able to press a button and have this button rebuild my WebView and load a new url. I need to destroy it no just set it GONE or INVISIBLE.
Thanks
UPDATE:
Button rbesatbtn = (Button) findViewById(R.id.btnrbesa);
rbesatbtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
wvr.destroy()
}
});
Button resttbtn = (Button) findViewById(R.id.btnrrest);
rrestbtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
WebView wvr = new WebView(this);
setContentView(wvr);
wvr = (WebView) findViewById(R.id.wVradios);
wvr.getSettings().setJavaScriptEnabled(true);
wvr.getSettings().setPluginsEnabled(true);
wvr.setWebViewClient(new WebViewClient());
wvr.setInitialScale(1);
wvr.getSettings().setBuiltInZoomControls(true);
wvr.getSettings().setUseWideViewPort(true);
});
The documentation says:
Destroy the internal state of the WebView. This method should be called after the WebView has been removed from the view system. No other methods may be called on a WebView after destroy.
So I guess that the answer is no. However, you can always initialize a new one...