Android json get sharedpreferences - android

i am trying to make get a json value to display on another class but it is returning a null value and i am trying to save it using sharedpreferences and it is not working . i want to get editor.putString("username", username); display the username on the next class which is menu . and it is displaying anon
public class MainActivity extends Activity {
Button login,signin,reg,forr;
private EditText user,pass;
private ProgressDialog pDialog;
int flag=0;
JSONParser jsonParser = new JSONParser();
private static String LOGIN_URL = "http://10.0.2.2/wordtinss/login.php";
private static final String TAG_SUCCESS = "success";
private static final String TAG_MESSAGE = "message";
private static final String DAIRY = "dairy";
public static final String PREFS_NAME = "LoginPrefs";
#Override
protected void onCreate(Bundle savedInstanceState) {
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectDiskReads().detectDiskWrites().detectNetwork()
.penaltyLog().build());
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
login=(Button)findViewById(R.id.login);
user=(EditText)findViewById(R.id.username);
pass=(EditText)findViewById(R.id.password);
reg=(Button) findViewById(R.id.reg);
forr=(Button) findViewById(R.id.forg);
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
if (settings.getString("logged", "").toString().equals("logged")) {
Intent intent = new Intent(MainActivity.this, Menu.class);
startActivity(intent);
}
reg.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent i = new Intent(MainActivity.this, Register.class);
finish();
startActivity(i);
}
//Close code that check online details
});
//Close log in
forr.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent i = new Intent(MainActivity.this, Forget.class);
finish();
startActivity(i);
}
//Close code that check online details
});
login.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//Check all fields
if(user.length()<1 || pass.length()<1)
{
Toast.makeText(MainActivity.this,"Please Enter both username and password", Toast.LENGTH_LONG).show();
return;
}
//check connectivity
if(!isOnline(MainActivity.this))
{
Toast.makeText(MainActivity.this,"No network connection", Toast.LENGTH_LONG).show();
return;
}
//from login.java
new loginAccess().execute();
}
//code to check online details
private boolean isOnline(Context mContext) {
ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnectedOrConnecting())
{
return true;
}
return false;
}
//Close code that check online details
});
//Close log in
}
class loginAccess extends AsyncTask<String, String, String> {
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(MainActivity.this);
pDialog.setMessage("Login...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
#Override
protected String doInBackground(String... arg0) {
// Check for success tag
int success;
String username = user.getText().toString();
String password = pass.getText().toString();
try {
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("username", username));
params.add(new BasicNameValuePair("password", password));
Log.d("request!", "starting");
// getting product details by making HTTP request
JSONObject json = jsonParser.makeHttpRequest(LOGIN_URL, "POST",
params);
// check your log for json response
Log.d("Login attempt", json.toString());
// json success tag
success = json.getInt(TAG_SUCCESS);
if (success == 1) {
Log.d("Login Successful!", json.toString());
// Clear all previous data in database
String dar=json.getString(DAIRY);
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("logged", "logged");
editor.putString("username", username);
editor.putString("dairy", dar);
editor.commit();
Intent i = new Intent(getApplicationContext(),Menu.class);
finish();
startActivity(i);
// Close all views before launching Dashboard
return json.getString(TAG_MESSAGE);
} else {
Log.d("Login Failure!", json.getString(TAG_MESSAGE));
return json.getString(TAG_MESSAGE);
}
} catch (JSONException e) {
}
return null;
}
protected void onPostExecute(String file_url) {
pDialog.dismiss();
if(flag==1)
Toast.makeText(MainActivity.this,"Please Enter Correct informations", Toast.LENGTH_LONG).show();
}
}
}
public class Menu extends Activity {
private List<list> myCars = new ArrayList<list>();
int flag=0;
String namee ,dar;
JSONParser jsonParser = new JSONParser();
private ProgressDialog pDialog;
private static final String TAG_SUCCESS = "success";
private static String LOGIN_URL = "http://10.0.2.2/wordtinss/login.php";
private static final String dairy= "dairy";
private static final String TAG_MESSAGE = "message";
public static final String PREFS_NAME = "LoginPrefs";
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menu);
populateCarlist();
populateListView();
registerclick();
SharedPreferences un = PreferenceManager.getDefaultSharedPreferences(Menu.this);
namee = un.getString("username", "anon");
TextView usern= (TextView) findViewById(R.id.usern);
usern.setText(namee);
}
}

Use:
namee = getSharedPreferences(PREFS_NAME , Context.MODE_PRIVATE).getString("username", "anon");
instead. Because I think you're using different preference files.

Related

ANDROID - Can't connect database from localhost in Android Device

My code is working in Android Emulator. I can connect to database from localhost...
But when I run in my Android Device. The app isn't run well..
Can you give reference for connect database from localhost to Android Device ? I have searched in Google, but I don't get it.
public class Login extends Activity implements View.OnTouchListener {
EditText usernameInput, passwordInput;
Button loginButton;
String username, password;
ProgressDialog pDialog;
JSONParser jsonParser = new JSONParser();
TextView createAccountLink;
private static String login_url = "http://10.0.2.2/ujian_online/login.php";
private static final String TAG_SUCCESS = "success";
private static final String TAG_PRODUCTS = "products";
ArrayList<HashMap<String, String>> arraylist;
JSONArray products = null;
String image_link;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
usernameInput = (EditText) findViewById(R.id.username);
passwordInput = (EditText) findViewById(R.id.password);
loginButton = (Button) findViewById(R.id.login_button);
jsonParser = new JSONParser();
createAccountLink = (TextView) findViewById(R.id.createAccountLabel);
createAccountLink.setOnTouchListener(this);
loginButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
new CheckAccounts().execute();
}
});
//HANCURIN SESSION
}
#Override
public boolean onTouch(View v, MotionEvent event) {
if(v.getId() == R.id.createAccountLabel) {
Intent i = new Intent(getApplicationContext(), Registration.class);
startActivity(i);
finish();
}
return true;
}
public class CheckAccounts extends AsyncTask<String, String, String> {
#Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(Login.this);
pDialog.setMessage("System checks your account.....");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
#Override
protected String doInBackground(String... args) {
username = usernameInput.getText().toString();
password = passwordInput.getText().toString();
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("username", username));
params.add(new BasicNameValuePair("password", password));
JSONObject json = jsonParser.makeHttpRequest(login_url, "POST", params);
try {
int success = json.getInt("success");
Log.d("SUKSES", String.valueOf(success));
int id = 0;
if (success == 1) {
products = json.getJSONArray(TAG_PRODUCTS);
for (int i = 0; i < products.length(); i++) {
JSONObject c = products.getJSONObject(i);
id = c.getInt("id");
}
new SessionManagement(getApplicationContext()).putInteger("ID", id);
Intent i = new Intent(getApplicationContext(), MainMenu.class);
startActivity(i);
finish();
} else {
pDialog.setMessage("Your username or password is wrong");
pDialog.show();
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String file_url) {
pDialog.dismiss();
}
}
}
Your are using 10.0.2.2 which is a special url for emulator ONLY to point to the machine localhost. For real devices use actual ip address of the machine and be on same network.
The url you are using should only be used in emulators.
Use it like this
private static String login_url = "http://real_ip_of_your_machine/ujian_online/login.php";
Get the ip of your maching using ipconfig(Windows) or ifconfig (Linux/Mac). Also, your machine and the device should be on same network.

How to add client side validation before execute asynctask?

Hello I am new to android,in my app I have Login page and it works fine with my response but I want to add something like this,if my user name and password edittext is blank and user click on login button it should show message instead of start async task.
public class LoginPage extends Activity implements OnClickListener{
private Button btn;
private EditText user;
private EditText pass;
// Alert Dialog Manager
AlertDialogManager alert = new AlertDialogManager();
// Session Manager Class
SessionManager session;
// Progress Dialog
private ProgressDialog pDialog;
//JSON parser class
JSONParser jsonParser = new JSONParser();
private Button btn1;
private String userid;
private static final String LOGIN_URL = "xxxxx";
private static final String TAG_SUCCESS = "status";
private static final String TAG_LOGIN = "login";
private static String TAG_USERID="user_login_id";
private static final String TAG_SESSION="session";
String session_id="";
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.login_page);
// Session Manager
session = new SessionManager(getApplicationContext());
user=(EditText)findViewById(R.id.loginmailid);
pass=(EditText)findViewById(R.id.loginpwd);
Toast.makeText(getApplicationContext(), "User Login Status: " + session.isLoggedIn(), Toast.LENGTH_LONG).show();
btn=(Button)findViewById(R.id.login);
btn1=(Button)findViewById(R.id.btnreg);
btn.setOnClickListener(this);
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.login:
if(user.equals(null) || pass.equals(null))
{
Toast.makeText(getApplicationContext(), "Enter Email and Password", Toast.LENGTH_SHORT).show();
}
else
{
new AttemptLogin().execute();
System.out.println("<<<<<<<<<<<<<<<<<<<<< Session ID : " + session_id);
session.createLoginSession(session_id);
System.out.println(session);
break;
}
case R.id.btnreg:
Intent i = new Intent(this, RegistrationForm.class);
startActivity(i);
break;
default:
break;
}
}
class AttemptLogin extends AsyncTask {
boolean failure = false;
#Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(LoginPage.this);
pDialog.setMessage("Login..");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
#SuppressWarnings("unused")
#Override
protected String doInBackground(String...args) {
//Check for success tag
//int success;
Looper.prepare();
String username = user.getText().toString();
String password = pass.getText().toString();
try {
//Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("email", username));
params.add(new BasicNameValuePair("password", password));
params.add(new BasicNameValuePair("version", "apps"));
Log.d("request!", "starting");
// getting product details by making HTTP request
JSONObject json = jsonParser.makeHttpRequest (
LOGIN_URL, "POST", params);
//check your log for json response
Log.d("Login attempt", json.toString());
JSONObject jobj = new JSONObject(json.toString());
final String msg = jobj.getString("msg");
session_id = jobj.getString("user_login_id");
System.out.println("Session ID : " + session_id);
System.out.println("MSG : " + msg);
runOnUiThread(new Runnable()
{
#Override
public void run()
{
Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
}
});
return json.getString(TAG_SUCCESS);
//JSONArray arr = json.getJSONArray("login");
//System.out.println(arr.toString());
//JSONObject arr1 = new JSONObject(json);
//String ss=arr1.getString("status");
//System.out.println(ss);
//System.out.println(arr1.getString("status"));
//String date = jObj.getString("status");
}catch (JSONException e) {
e.printStackTrace();
}
return null;
}
// After completing background task Dismiss the progress dialog
protected void onPostExecute(String file_url) {
//dismiss the dialog once product deleted
pDialog.dismiss();
if(file_url.equals("success")) {
session.createLoginSession(session_id);
// Log.d("Login Successful!", json.toString());
Intent i = new Intent(LoginPage.this, MainActivity.class);
i.putExtra("id", session_id);
System.out.println("Session Id : >>>>>>>>>>>>>>>>" + session_id);
startActivity(i);
}else{
//Toast.makeText(getApplicationContext(), "Failed", Toast.LENGTH_LONG).show();
}
}}
}
try like this,
if(user.getText().toString().trim().length() > 0 && pass.getText().toString().trim().length() > 0)
{
new AttemptLogin().execute();
System.out.println("<<<<<<<<<<<<<<<<<<<<< Session ID : " + session_id);
session.createLoginSession(session_id);
System.out.println(session);
break;
}
else
{
Toast.makeText(getApplicationContext(), "Enter Email and Password", Toast.LENGTH_SHORT).show();
}
try it this way...
case R.id.login:
if(user.getText().toString().trim().length()==0 || pass.getText().toString().trim().length()==0)
{
Toast.makeText(getApplicationContext(), "Enter Email and Password", Toast.LENGTH_SHORT).show();
}
else
{
new AttemptLogin().execute();
System.out.println("<<<<<<<<<<<<<<<<<<<<< Session ID : " + session_id);
session.createLoginSession(session_id);
System.out.println(session);
break;
}

make a string from AsyncTask not null in onCreate

I have a problem i need the token to transfer it to my SessionManagement class to compare it with the saved token , but in my onCreate it's always null ,i need a workaround to make my token not null in oncreate
please help.
here is my code
private static final String LOGIN_URL = "http://baymd.myterranet.com/api/auth";
private static final String TAG_SUCCESS = "code";
private static final String TAG_MESSAGE = "message";
private static final String TAG_DATA = "data";
private static final String TAG_TOKEN = "access_token";
JSONParser jsonParser = new JSONParser();
private EditText user, pass;
private Button mSubmit;
private ProgressDialog pDialog;
private String token, none,SavedToken;
SesionManagement session;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
session=new SesionManagement(getApplicationContext());
HashMap<String, String> tokens = session.getUserDetails();
SavedToken = tokens.get(session.KEY_NAME);
if(token==null) {//This line
Log.d("TOKEN ====== ", "NULLL");
}
session.checkLogin(token, SavedToken);
user = (EditText) findViewById(R.id.inputEmail);
pass = (EditText) findViewById(R.id.inputPass);
mSubmit = (Button) findViewById(R.id.loginBtn);
mSubmit.setOnClickListener(this);
}
#Override
public void onClick(View v) {
new AttemptLogin().execute();
}
class AttemptLogin extends AsyncTask<String, String, String> {
#Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(Login.this);
pDialog.setMessage("Attempting login...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
#Override
protected String doInBackground(String... args) {
int success;
String username = user.getText().toString();
String password = pass.getText().toString();
try {
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("email", username));
params.add(new BasicNameValuePair("password", password));
JSONObject json = jsonParser.makeHttpRequest(
LOGIN_URL, "POST", params, none);
success = json.getInt(TAG_SUCCESS);
if (success == 200) {
JSONObject c = json.getJSONObject(TAG_DATA);
token = c.getString(TAG_TOKEN);//The token wich is null in oncreate
Intent i = new Intent(Login.this, NavDraver.class);
i.putExtra("cjson", c.toString());
finish();
startActivity(i);
return json.getString(TAG_MESSAGE);
} else {
Log.d("Login Failure!", json.getString(TAG_MESSAGE));
json.getString(TAG_MESSAGE);
return json.getString(TAG_MESSAGE);
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
#Override
protected void onPostExecute(String s) {
session.createLoginSession(token);
Log.d("SAVED TOKEN",SavedToken);
pDialog.dismiss();
}
}
}
Try this:
token = c.optString(TAG_TOKEN, yourDefaultValueHere);
if(token == null){
token = ""; // or whatever you want to init here
}
Hope it helps.

Login should be succesful but does not link to my main menu interface

This is my logcat
12-08 14:45:21.179: D/request!(6046): starting
12-08 14:45:21.719: D/Login attempt(6046): {"message":"Login successful!","success":1}
This is my Login.java
public class Login extends ActionBarActivity implements OnClickListener {
private Button login,register;
private EditText email,password;
// Progress Dialog
private ProgressDialog pDialog;
JSONParser jsonParser = new JSONParser();
private static final String LOGIN_URL = "http://192.168.1.14:1234/PMSS/login.php";
//JSON element ids from repsonse of php script:
private static final String TAG_SUCCESS = "success";
private static final String TAG_MESSAGE = "message";
#SuppressLint("NewApi")
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
login = (Button) findViewById(R.id.login);
register = (Button) findViewById(R.id.registerlauncher);
email = (EditText) findViewById(R.id.userid);
password = (EditText) findViewById(R.id.password);
login.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
String Username = email.getText().toString();
String Password = password.getText().toString();
new AttemptLogin(Username,Password).execute();
}
});
register.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(Login.this, Register.class);
startActivity(intent);
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
// For the main activity, make sure the app icon in the action bar
// does not behave as a button
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.login, menu);
return true;
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
/*case R.id.login:
new AttemptLogin().execute();
break;
case R.id.register:
Intent i = new Intent(Login.this, Register.class);
startActivity(i);
break;
*/
default:
break;
}
}
//AsyncTask is a seperate thread than the thread that runs the GUI
//Any type of networking should be done with asynctask.
class AttemptLogin extends AsyncTask<String, String, String> {
//three methods get called, first preExecture, then do in background, and once do
//in back ground is completed, the onPost execture method will be called.
boolean failure = false;
String res;
String Username;
String Password;
int success;
public AttemptLogin(String Username, String Password) {
this.Username = Username;
this.Password = Password;
}
#Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(Login.this);
pDialog.setMessage("Attempting login...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
protected String doInBackground(String... args) {
try {
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("username", Username));
params.add(new BasicNameValuePair("password", Password));
Log.d("request!", "starting");
// getting product details by making HTTP request
JSONObject json = jsonParser.makeHttpRequest(
LOGIN_URL, "POST", params);
System.out.print("Here");
// check your log for json response
Log.d("Login attempt", json.toString());
// json success tag
success = json.getInt(TAG_SUCCESS);
res = json.getString(TAG_MESSAGE);
return res;
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(int success) {
// dismiss the dialog once product deleted
pDialog.dismiss();
if (success == 1) {
Log.d("Login Successful!", res);
Intent i = new Intent(Login.this, MainMenu.class);
startActivity(i);
Toast.makeText(Login.this, res, Toast.LENGTH_LONG).show();
}else{
Log.d("Login Failure!", res);
Toast.makeText(Login.this, res, Toast.LENGTH_LONG).show();
}
}
}
}
As the logcat said I login succesfully but in my android phone still having the Attemping Login... and it will not go to my MainMenu interface. There is no compilation and runtime errors. I was wonder Intent i = new Intent(Login.this,MainMenu.class); and startActivity(i); does not work?
You should return success instead of res from your doInBackground. There is also something wrong with the types (arguments, return) of the various methods in AsyncTask. The return type of doInBackground should be the same as the argument type of onPostExecute.
Change your code like this:
class AttemptLogin extends AsyncTask<String, String, Integer> {
...
protected Integer doInBackground(String... args) {
...
return success;
}
protected void onPostExecute(Integer success) {
...
}
}

Activity has leaked window.com.android.internal.policy.impl.PhoneWindow$DecorView

public class Login extends Activity implements OnClickListener {
private EditText user, pass;
private Button mSubmit, mRegister;
// Progress Dialog
private ProgressDialog pDialog;
// JSON parser class
JSONParser jsonParser = new JSONParser();
private static final String LOGIN_URL = "http://192.168.2.4/mybringbacktutorial/login.php";
private static final String TAG_SUCCESS = "success";
private static final String TAG_MESSAGE = "message";
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
// setup input fields
user = (EditText) findViewById(R.id.username);
pass = (EditText) findViewById(R.id.password);
// setup buttons
mSubmit = (Button) findViewById(R.id.login);
mRegister = (Button) findViewById(R.id.register);
// register listeners
mSubmit.setOnClickListener(this);
mRegister.setOnClickListener(this);
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.login:
new AttemptLogin().execute();
break;
case R.id.register:
Intent i = new Intent(this, Register.class);
startActivity(i);
break;
default:
break;
}
}
class AttemptLogin extends AsyncTask<String, String, String> {
#Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(Login.this);
pDialog.setMessage("Attempting login...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
#Override
protected String doInBackground(String... args) {
// TODO Auto-generated method stub
// Check for success tag
int success;
String username = user.getText().toString();
String password = pass.getText().toString();
try {
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("username", username));
params.add(new BasicNameValuePair("password", password));
Log.d("request!", "starting");
// getting product details by making HTTP request
JSONObject json = jsonParser.makeHttpRequest(LOGIN_URL, "POST",
params);
// check your log for json response
Log.d("Login attempt", json.toString());
// json success tag
success = json.getInt(TAG_SUCCESS);
if (success == 1) {
Log.d("Login Successful!", json.toString());
// save user data
SharedPreferences sp = PreferenceManager
.getDefaultSharedPreferences(Login.this);
Editor edit = sp.edit();
edit.putString("username", username);
edit.commit();
Intent i = new Intent(Login.this, ReadComments.class);
finish();
startActivity(i);
return json.getString(TAG_MESSAGE);
} else {
Log.d("Login Failure!", json.getString(TAG_MESSAGE));
return json.getString(TAG_MESSAGE);
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
#Override
protected void onPostExecute(String file_url) {
// dismiss the dialog once product deleted
pDialog.dismiss();
if (file_url != null) {
Toast.makeText(Login.this, file_url, Toast.LENGTH_LONG).show();
}
}
}
}
Guys how to create user session here in this code? i want ReadComments.class to have a logout button and when user press the back button the session of the log in user will not be destroy, also when application is close, if the app. is open again the user has the his log in still there.
In your doInBackground of AttemptLogin class try to add pDialog.dismiss(); before you call finish() when if (success == 1)
in your onDestory() check whether the dialog is showing or not if showing dismiss it like this..
#Override
protected void onDestroy() {
if (pDialog != null) {
if (pDialog.isShowing()) {
pDialog.dismiss();
pDialog = null;
}
}
super.onDestroy();
}

Categories

Resources