Skip to content

Commit

Permalink
logout button
Browse files Browse the repository at this point in the history
  • Loading branch information
iamsh4shank committed Dec 27, 2019
1 parent 0cd5756 commit c1273f3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.example.android.codeforces.Activities;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
Expand All @@ -17,7 +20,14 @@ public class ProfileActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile);

Button btn = (Button)findViewById(R.id.logOut);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(ProfileActivity.this, MainActivity.class));
logOut();
}
});
try {
JSONObject jsonObject = new JSONObject(getIntent().getStringExtra("profile"));
JSONObject data = jsonObject.getJSONArray("result").getJSONObject(0);
Expand Down Expand Up @@ -56,4 +66,8 @@ protected void onCreate(Bundle savedInstanceState) {
e.printStackTrace();
}
}
public void logOut(){
Intent intent = new Intent(this,MainActivity.class);
startActivity(intent);
}
}
8 changes: 8 additions & 0 deletions app/src/main/res/layout/activity_profile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -245,5 +245,13 @@
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>

<Button
android:id="@+id/logOut"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="@string/LogOut"
android:theme="@android:style/Theme.Holo" />
</LinearLayout>
</ScrollView>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
<string name="old_rating">Old Rating: </string>
<string name="rating_change">Change: </string>
<string name="new_rating">New Rating: </string>
<string name="LogOut">Log Out</string>
</resources>

0 comments on commit c1273f3

Please sign in to comment.