Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -18,6 +21,18 @@ 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 +71,8 @@ protected void onCreate(Bundle savedInstanceState) {
e.printStackTrace();
}
}
public void logOut(){
Intent intent = new Intent(this,MainActivity.class);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we give the direct intent then when we press the back button then it will come back the previous activity so, App will crashes by taking 2 usernames avoid that behaviour

startActivity(intent);
}
}
7 changes: 7 additions & 0 deletions app/src/main/res/layout/activity_profile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,13 @@
android:layout_height="wrap_content"
/>
</LinearLayout>
<Button
android:id="@+id/logOut"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="@string/log_out"
android:theme="@android:style/Theme.Holo" />
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
Expand Down
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="log_out">Log Out</string>
</resources>