I am getting a runtime exception when I am calling NavDrawerActivity from LoginScreen activity.
Error
java.lang.RuntimeException: Performing stop of activity that is not
resumed:
{com.example.owner.loginapp/com.example.owner.loginapp.NavDrawerActivity}
How to fix this error?
Here is my loginScreen code
package com.example.owner.loginapp;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;
import android.content.SharedPreferences;
public class LoginScreen extends AppCompatActivity {
ImageView image;
ImageView user_img;
ImageView pass_img;
Button log_in;
Button reg;
EditText editText_Username;
EditText editText_Pass;
UserSessionManager session;
private SharedPreferences sharedPreferences;
private static final String PREFER_NAME = "Reg";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
session = new UserSessionManager(getApplicationContext());
image = (ImageView) findViewById(R.id.imageView);
image.setImageResource(R.drawable.smile);
user_img = (ImageView) findViewById(R.id.user_img);
user_img.setImageResource(R.drawable.user_img);
pass_img = (ImageView) findViewById(R.id.pass_img);
pass_img.setImageResource(R.drawable.img_pass);
log_in = (Button) findViewById(R.id.btn_Login);
reg = (Button) findViewById(R.id.btn_Reg);
editText_Username = (EditText) findViewById(R.id.editText_UserName);
editText_Pass = (EditText) findViewById(R.id.editText_Password);
Bitmap icon = BitmapFactory.decodeResource(getResources(),
image.setImageBitmap(icon);
Toast.makeText(getApplicationContext(),
"User Login Status: " + session.isUserLoggedIn(),
Toast.LENGTH_LONG).show();
sharedPreferences = getSharedPreferences(PREFER_NAME, Context.MODE_PRIVATE);
log_in.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String username = editText_Username.getText().toString();
String password = editText_Pass.getText().toString();
if (username.trim().length() > 0 && password.trim().length() > 0) {
String uName = null;
String uPassword = null;
if (sharedPreferences.contains("Name")) {
uName = sharedPreferences.getString("Name", "");
}
if (sharedPreferences.contains("Password")) {
uPassword = sharedPreferences.getString("Password", "");
}
if (username.equals(uName) && password.equals(uPassword)) {
session.createUserLoginSession(uName, uPassword);
Intent i = new Intent(getApplicationContext(), NavDrawerActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
} else {
Toast.makeText(getApplicationContext(),
"Username/Password is incorrect",
Toast.LENGTH_LONG).show();
}
} else {
Toast.makeText(getApplicationContext(),
"Please enter username and password",
Toast.LENGTH_LONG).show();
}
}
});
reg.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
setContentView(R.layout.register);
Intent i = new Intent(getApplicationContext(), Reg.class);
startActivity(i);
}
});
}
}
I copied your code and tried to instantiate a Reg Activity class that I designed and everything worked fine. It is possible that you are doing something wrong in the 1onResumeoronCreate` of Reg class.
Post that class too for more information.
Related
I have this Javascript code for login in my app. it working fine but how can I add a checkbox for remember username and password to this code to my project? Is there some one out there that can help me? Thanks for all help
package no.vfk.vfkhakkespettboka;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class Login_backup extends AppCompatActivity {
private EditText Name;
private EditText Password;
private TextView Info;
private Button Login;
private int counter = 6;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
Name = (EditText)findViewById(R.id.etName);
Password = (EditText)findViewById(R.id.etPassword);
Info = (TextView)findViewById(R.id.tvInfo);
Login = (Button)findViewById(R.id.btnLogin);
Info.setText("No attempt remains: 6");
Login.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
validate(Name.getText().toString(), Password.getText().toString());
}
});
}
private void validate(String userName, String userPassword){
if((userName.equals("test")) && (userPassword.equals("test123"))){
Intent intent = new Intent(Login_backup.this, Home.class);
startActivity(intent);
}else{
counter--;
Info.setText("No attempt remains: " + String.valueOf(counter));
if(counter == 0){
Login.setEnabled(false);
}
}
}
}
I'm trying to make an APK that saves passwords with the site using two different ArrayLists. This way, I can get the right indexnumber of the site and get the password based on this indexnumber. In the beginning of MainActivity, I add two random Strings to the ArrayLists, so that I don't have to work with empty ArrayLists, but this is utterly useless I think.
The problem is I can only view the last site-password I have put in. Previous combinations are "lost."
code:
MainActivity.java
package com.example.prive.passwordsafe;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
public ArrayList<String> passwordList = new ArrayList<>();
public ArrayList<String> siteList = new ArrayList<>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
passwordList.add("ejifjejfijeifjeijfiejifjeijfiejfijefie");
siteList.add("iejfijeifjiejfiejidvjijijeijivjiejvijeivjejv");
Button addButton = (Button) findViewById(R.id.addButton);
Button showButton = (Button) findViewById(R.id.showButton);
addButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
firstIntent();
}
});
showButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
secondIntent();
}
});
}
#Override
public void onResume(){
super.onResume();
add();
}
private void firstIntent() {
Intent intent = new Intent(MainActivity.this, addActivity.class);
intent.putStringArrayListExtra("passwordList", passwordList);
intent.putStringArrayListExtra("siteList", siteList);
startActivity(intent);
}
private void secondIntent() {
Intent intent = new Intent(MainActivity.this, showActivity.class);
intent.putStringArrayListExtra("passwordList", passwordList);
intent.putStringArrayListExtra("siteList", siteList);
startActivity(intent);
}
public void add(){
Bundle pickupData = getIntent().getExtras();
if(pickupData == null){
return;
}
String receivedPassword = pickupData.getString("Password");
String receivedSite;
receivedSite = pickupData.getString("Site");
passwordList.add(receivedPassword);
siteList.add(receivedSite);
}
}
addActivity.java
package com.example.prive.passwordsafe;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class addActivity extends AppCompatActivity {
public EditText siteInsert, passwordInsert;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_toevoeg);
siteInsert = (EditText) findViewById(R.id.siteInsert);
passwordInsert = (EditText) findViewById(R.id.passwordInsert);
siteInsert.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Toast msg = Toast.makeText(getBaseContext(), "site", Toast.LENGTH_LONG);
msg.show();
}
});
passwordInsert.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Toast msg = Toast.makeText(getBaseContext(), "password", Toast.LENGTH_LONG);
msg.show();
}
});
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
String password = passwordInsert.getText().toString();
String site = siteInsert.getText().toString();
Intent intent = new Intent(addActivity.this, MainActivity.class);
intent.putExtra("Password", password);
intent.putExtra("Site", site);
startActivity(intent);
}
});
}
}
showActivity.java
package com.example.prive.passwordsafe;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
public class showActivity extends AppCompatActivity {
public EditText editText;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_toon);
Button showButton = (Button) findViewById(R.id.showButton);
Button backButton = (Button) findViewById(R.id.backButton);
editText = (EditText) findViewById(R.id.editText);
final TextView textView = (TextView) findViewById(R.id.textView);
Bundle pickupData = getIntent().getExtras();
final ArrayList<String> passwordList = pickupData.getStringArrayList("passwordList");
final ArrayList<String> siteList = pickupData.getStringArrayList("siteList");
editText.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Toast msg = Toast.makeText(getBaseContext(), "site", Toast.LENGTH_LONG);
msg.show();
}
});
if (passwordenList != null && siteList != null) {
showButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
int numberOfPasswords = passwordenList.size();
for (int i = 0; i <= numberOfPasswords; i++) {
String password;
String temporary = editText.getText().toString();
if (temporary.equals(siteList.get(i))) {
password = passwordList.get(i);
textView.setText(password);
}else{
password = "wrong input";
textView.setText(password);
}
}
}
});
}else{
return;
}
backButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
finish();
}
});
}
}
When you exit an Activity, all the data on it is lost. You have to persist your ArrayList in SQLite or use SharedPreferences instead.
SharedPreferences: https://developer.android.com/reference/android/content/SharedPreferences.html
SQLite: https://developer.android.com/training/basics/data-storage/databases.html
import android.content.Intent;
import android.content.SharedPreferences;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import java.util.Random;
public class MainActivity extends AppCompatActivity {
TextView t1,t2;
Button generate1;
MediaPlayer pickupgold, pickupplatinum;
SharedPreferences mySharedPreferences;
private static Button button2;
#Override
protected void onCreate(Bundle savedInstanceState) {
mySharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
pickupgold = MediaPlayer.create(this, R.raw.pickup_gold);
pickupplatinum = MediaPlayer.create(this, R.raw.pickup_platinum);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
OnClickButtonListener();
final ImageView imageView = (ImageView) findViewById(R.id.imageView);
final ImageView imageView2 = (ImageView) findViewById(R.id.imageView2);
t1 = (TextView) findViewById(R.id.textView3);
t2 = (TextView) findViewById(R.id.textView8);
generate1 = (Button) findViewById(R.id.button);
generate1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
TextView userTextEntry = (TextView) findViewById(R.id.textView3);
String userData = userTextEntry.getText().toString();
int num2 = mySharedPreferences.getInt("INT_KEY1", Integer.parseInt(userData));
int num3 = mySharedPreferences.getInt("INT_KEY2", -1);
Intent intent = new Intent(MainActivity.this, SecondActivity.class);
intent.putExtra("parameter1", num2);
Random rand = new Random();
int num1 = rand.nextInt(100);
if (num1 % 2 == 0) {
pickupgold.start();
num2 += 1;
SharedPreferences.Editor editor = mySharedPreferences.edit();
editor.putInt("INT_KEY1", num2);
editor.apply();
t1.setText(String.format("%d", num2));
imageView.startAnimation(AnimationUtils.loadAnimation(MainActivity.this, android.R.anim.slide_in_left));
Toast.makeText(getApplicationContext(), R.string.foundgold2, Toast.LENGTH_LONG).show();
}else{
Toast.makeText(getApplicationContext(), R.string.notfoundgold, Toast.LENGTH_LONG).show();
} if (num1 == 1){
pickupplatinum.start();
num3 += 1;
SharedPreferences.Editor editor = mySharedPreferences.edit();
editor.putInt("INT_KEY2", num3);
editor.apply();
t2.setText(String.format("%d", num3));
imageView2.startAnimation(AnimationUtils.loadAnimation(MainActivity.this, android.R.anim.slide_in_left));
Toast.makeText(getApplicationContext(), R.string.foundplatinum1, Toast.LENGTH_LONG).show();
}
}
});
}
public void OnClickButtonListener() {
button2 = (Button)findViewById(R.id.button2);
button2.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent("com.example.tans.goldminer1.SecondActivity");
startActivity(intent);
}
}
);
}
This is MainActivity.java
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;
public class SecondActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Intent intent = getIntent();
int goldamountval = intent.getIntExtra("parameter1", 0);
TextView goldamount = (TextView) findViewById(R.id.goldamount);
goldamount.setText("" + goldamountval);
}
and This is SecondActivity.java
I think the int value should be loaded from MainActivity.java but
When I go to SecondActivity, It does not seem to appear, Just showing 0.
What's the reason and how can i solve it? and Sorry, My Code may look like confused. :<
Try this on SecondActivity
Intent intent = new Intent(MainActivity.this, SecondActivity.class);
intent.putExtra("parameter1", num2);
startActivity(intent );
You need to start the SecondActivity after the first two lines :
Intent intent = new Intent(MainActivity.this, SecondActivity.class);
intent.putExtra("parameter1", num2);
startActivity(intent);
Intent intent = new Intent(context, YourActivityClass.class);
intent.putExtra(KEY, );
startActivity(intent);
Seocnd Activity-
Intent intent = getIntent();
if (null != intent) {
String stringData= intent.getStringExtra(KEY);
int numberData = intent.getIntExtra(KEY, defaultValue);
boolean booleanData = intent.getBooleanExtra(KEY, defaultValue);
char charData = intent.getCharExtra(KEY, defaultValue);
}
I want to create simple application in which i want to show bluetooth devices..but when i press the button, Application crashes..
in ActivityMain.java this method will go to next activity (Activity.java)..in which i am getting problem..Rest of buttons are working
ActivityMain.java
package com.example.bluetoothcheck5;
import java.util.Set;
import com.example.bluetoothcheck5.Activity2;
import android.os.Bundle;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
private static final int REQUEST_ENABLE_BT = 0;
private static final int REQUEST_DISCOVERABLE_BT = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView out=(TextView)findViewById(R.id.out);
final Button button = (Button) findViewById(R.id.button1);
final Button button1 = (Button) findViewById(R.id.button2);
final Button button2 = (Button) findViewById(R.id.button3);
final Button buttonSearch = (Button) findViewById(R.id.buttonSearch);
final BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBluetoothAdapter == null) {
out.append("device not supported");
}
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (!mBluetoothAdapter.isEnabled()) {
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
}
}
});
button1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
if (!mBluetoothAdapter.isDiscovering()) {
Context context = getApplicationContext();
CharSequence text = "MAKING YOUR DEVICE DISCOVERABLE";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
startActivityForResult(enableBtIntent, REQUEST_DISCOVERABLE_BT);
}
}
});
button2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
mBluetoothAdapter.disable();
Context context = getApplicationContext();
CharSequence text = "TURNING_OFF BLUETOOTH";
Toast toast = Toast.makeText(context, text, Toast.LENGTH_LONG);
toast.show();
Set<BluetoothDevice> mPairedDevices = mBluetoothAdapter.getBondedDevices();
if (mPairedDevices.size() > 0)
{
for (BluetoothDevice mDevice : mPairedDevices)
{
Log.v("Title", "PairedDevices: " + mDevice.getName() + " " + mDevice.getAddress());
}
}
}
});
buttonSearch.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent myIntent = new Intent(arg0.getContext(), Activity2.class);
// myIntent.setClass(MainActivity.this, Activity2.class);
// startActivityForResult(myIntent, REQUEST_PAIRED_DEVICE);
startActivity(myIntent);
}
});
}}
Activity2.java
package com.example.bluetoothcheck5;
import java.util.Set;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
import com.example.bluetoothcheck5.R;
import com.example.bluetoothcheck5.MainActivity;
public class Activity2 extends MainActivity {
protected static final String TAG = "TAG";
private BluetoothAdapter mBluetoothAdapter;
private ArrayAdapter<String> mPairedDevicesArrayAdapter;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_2);
mPairedDevicesArrayAdapter = new ArrayAdapter<String>(this, R.layout.activity_2);
ListView mPairedListView = (ListView) findViewById(R.id.listView1);
mPairedListView.setAdapter(mPairedDevicesArrayAdapter);
mPairedListView.setOnItemClickListener(mDeviceClickListener);
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
Set<BluetoothDevice> mPairedDevices = mBluetoothAdapter.getBondedDevices();
if (mPairedDevices.size() > 0)
{
findViewById(R.id.title_paired_devices).setVisibility(View.VISIBLE);
for (BluetoothDevice mDevice : mPairedDevices)
{
mPairedDevicesArrayAdapter.add(mDevice.getName() + "\n" + mDevice.getAddress());
}
}
else
{
String mNoDevices = getResources().getText(R.string.none_paired).toString();
mPairedDevicesArrayAdapter.add(mNoDevices);
}
}
private OnItemClickListener mDeviceClickListener = new OnItemClickListener()
{
public void onItemClick(AdapterView<?> mAdapterView, View mView, int mPosition, long mLong)
{
mBluetoothAdapter.cancelDiscovery();
String mDeviceInfo = ((TextView) mView).getText().toString();
String mDeviceAddress = mDeviceInfo.substring(mDeviceInfo.length() - 17);
Log.v(TAG, "Device_Address " + mDeviceAddress);
Bundle mBundle = new Bundle();
mBundle.putString("DeviceAddress", mDeviceAddress);
Intent mBackIntent = new Intent();
mBackIntent.putExtras(mBundle);
setResult(Activity.RESULT_OK, mBackIntent);
finish();
}
};
}
i made sample project to demonstrate bluetooth disovering, pair or unpair device. Find it here,
http://www.londatiga.net/it/programming/android/how-to-programmatically-scan-or-discover-android-bluetooth-device/
I have an application that displays a splash screen then a 'Showonce' screen, I have used app prefs and a boolean "user_accept" to decide wether the screen gets displayed or not, trouble no matter if the boolean = true it still shows the page, please see my code for the pages, any help greatly appreciated :).
package com.overclockerz.webtest;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.view.Window;
import android.widget.Toast;
public class SplashScreen extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.splash_layout);
final SharedPreferences settings = getSharedPreferences("APP_PREFS",
MODE_PRIVATE);
final boolean hasAgreed = settings.getBoolean("user_accepted", false);
Handler handler = new Handler();
// run a thread after 2 seconds to start the home screen
handler.postDelayed(new Runnable() {
#Override
public void run() {
if (hasAgreed == false){
Intent intent = new Intent(SplashScreen.this, ShowOnce.class);
SplashScreen.this.startActivity(intent);
Toast.makeText(getApplicationContext(), "DEBUG: USER HAS NOT ACCEPTED",Toast.LENGTH_LONG).show();
}else if (hasAgreed == true){
Toast.makeText(getApplicationContext(), "DEBUG: USER HAS ACCEPTED",Toast.LENGTH_LONG).show();
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
finish();
}
finish();
}
}, 2000); // time in milliseconds (1 second = 1000 milliseconds) until the run() method will be called
}
}
package com.overclockerz.webtest;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.Toast;
public class ShowOnce extends Activity implements OnClickListener {
Button show_options_dialog, accept_button;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.show_once);
show_options_dialog = (Button) findViewById(R.id.show_options_dialog);
accept_button = (Button) findViewById(R.id.accept_button);
show_options_dialog.setOnClickListener(this);
accept_button.setOnClickListener(this);
}
#Override
public void onClick(View v) {
if (v == show_options_dialog){
Intent intent = new Intent(getApplicationContext(), SettingScreen.class);
startActivity(intent);
}
else if (v == accept_button){
SharedPreferences settings = getSharedPreferences("APP_PREFS",
MODE_PRIVATE);
SharedPreferences.Editor prefEditor = settings.edit();
prefEditor.putBoolean("user_accept", true);
Toast.makeText(getApplicationContext(), "DEBUG: USER CLICKED ACCEPT", Toast.LENGTH_LONG).show();
prefEditor.commit();
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
finish();
}
}
}
you are saving user_accept and checking for user_accepted
Please use public static final String to avoid such problems:
public static final String USER_ACCEPTED = "accepted";
.........
prefEditor.putBoolean(USER_ACCEPTED , true);
.........
settings.getBoolean(USER_ACCEPTED , false);