New way of referencing deprecated xml prefrence - android

I work with preference xml file as options menu and i use it in my java class like bellwo
but the compiler says its deprecated and add a black line on addpreffrencefromresource(R.xml.mypreff). what is the new way of coding for it? thank you for helping.
package com.bestdiet;
import android.content.Intent;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.view.MenuItem;
public class prefs extends PreferenceActivity{
#SuppressWarnings("deprecation")
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.mypref);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
// return super.onOptionsItemSelected(item);
switch(item.getItemId())
{
case R.id.exit:
finish();
break;
case R.id.help:
break;
case R.id.options:
break;
}
return false;
}
xml file:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<CheckBoxPreference
android:title="پخش صدا"
android:defaultValue="true"
android:key="checkbox1"
/>
<CheckBoxPreference
android:title="پخش موسیقی"
android:defaultValue="true"
android:key="checkbox2"/>
</PreferenceScreen>

There is something notable: I just used the same xml preference layout...
But nobody tells you not to use two different files (say prefs_old.xml and prefs_new.xml), to add some of the new features to the (new) PreferenceFragment version of your PreferenceScreen.
This is my PreferenceActivity. It simply checks the build version to see which version of the preferences must be prepared:
package com.example.android.scheduler2;
/* ---------------------------------- Imports ------------------------------- */
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
import android.widget.ListView;
public final class ACT_Prefs
extends PreferenceActivity
implements OnSharedPreferenceChangeListener
{
/* ------------------------------ Objects ------------------------------- */
private Context ctx = null;
/* ----------------------------- Overrides ------------------------------ */
#Override
public final void onCreate(final Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
ctx = getApplicationContext();
if (Build.VERSION.SDK_INT < 11)
{
createPreference_Activity();
}
else
{
createPreference_Fragment();
}
}
#Override
protected void onPause()
{
// Unregister OnSharedPreferenceChangeListener
PreferenceManager.getDefaultSharedPreferences(ctx).
unregisterOnSharedPreferenceChangeListener(this);
// Call base method
super.onPause();
}
#Override
protected void onResume()
{
// Register OnSharedPreferenceChangeListener
PreferenceManager.getDefaultSharedPreferences(ctx).
registerOnSharedPreferenceChangeListener(this);
// Fire base method
super.onResume();
}
#Override
public void onSharedPreferenceChanged
(final SharedPreferences sharedPreferences, final String key)
{
// ... Do whatever you need to do here ...
System.out.println(key + " changed!!");
}
/* ------------------------------ Methods ------------------------------- */
//#SuppressWarnings("deprecation")
private final void createPreference_Activity()
{
addPreferencesFromResource(R.xml.prefs);
}
#SuppressLint("NewApi")
private final void createPreference_Fragment()
{
getFragmentManager().beginTransaction().replace
(android.R.id.content, new FRG_Prefs()).commit();
getFragmentManager().executePendingTransactions();
}
}
This is FRG_Prefs (the PreferenceFragment)
package com.example.android.scheduler2;
/* ---------------------------------- Imports ------------------------------- */
import android.annotation.SuppressLint;
import android.graphics.PixelFormat;
import android.preference.PreferenceFragment;
import android.view.View;
import android.widget.ListView;
#SuppressLint("NewApi")
public final class FRG_Prefs
extends PreferenceFragment
{
/* ----------------------------- Overrides ------------------------------ */
#Override
public final void onResume()
{
super.onResume();
addPreferencesFromResource(R.xml.prefs);
}
}

Related

Android Preferences - change font size by user

I am looking for a solution for my app to let the user select the font size via settings menu. Like I am able to do in other apps e.g. Jota+. Here are some screen shots for a better understanding (sorry - my Jota+ is a German version):
As of now I installed already a settingsActivity which is using a FragmentManager to call a PreferenceFragment using my pref_main.xml as resource.
Any idea how I can archive this?
My SettingsActivity:
package com.wbapps.wbshoppinglist;
/**
* Created by Andreas on 2/15/2018.
*/
import android.os.Bundle;
import android.preference.EditTextPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import android.view.MenuItem;
public class SettingsActivity extends AppCompatPreferenceActivity {
private static final String TAG = SettingsActivity.class.getSimpleName();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
// load settings fragment
getFragmentManager().beginTransaction().replace(android.R.id.content, new MainPreferenceFragment()).commit();
}
public static class MainPreferenceFragment extends PreferenceFragment {
#Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.pref_main);
}
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
onBackPressed();
}
return super.onOptionsItemSelected(item);
}
private static void bindPreferenceSummaryToValue(Preference preference) {
preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);
sBindPreferenceSummaryToValueListener.onPreferenceChange(preference,
PreferenceManager
.getDefaultSharedPreferences(preference.getContext())
.getString(preference.getKey(), ""));
}
/**
* A preference value change listener that updates the preference's summary
* to reflect its new value.
*/
private static Preference.OnPreferenceChangeListener sBindPreferenceSummaryToValueListener = new Preference.OnPreferenceChangeListener() {
#Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
String stringValue = newValue.toString();
if (preference instanceof ListPreference) {
// For list preferences, look up the correct display value in
// the preference's 'entries' list.
ListPreference listPreference = (ListPreference) preference;
int index = listPreference.findIndexOfValue(stringValue);
// Set the summary to reflect the new value.
preference.setSummary(
index >= 0
? listPreference.getEntries()[index]
: null);
}
else if (preference instanceof EditTextPreference) {
if (preference.getKey().equals("key_gallery_name")) {
// update the changed gallery name to summary filed
preference.setSummary(stringValue);
}
} else {
preference.setSummary(stringValue);
}
return true;
}
};
}
My AppCompatPreferenceActivity:
package com.wbapps.wbshoppinglist;
/**
* Created by Andreas on 2/15/2018.
*/
import android.content.res.Configuration;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatDelegate;
import android.support.v7.widget.Toolbar;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;
/**
* A {#link PreferenceActivity} which implements and proxies the necessary calls
* to be used with AppCompat.
*/
public abstract class AppCompatPreferenceActivity extends PreferenceActivity {
private AppCompatDelegate mDelegate;
#Override
protected void onCreate(Bundle savedInstanceState) {
getDelegate().installViewFactory();
getDelegate().onCreate(savedInstanceState);
super.onCreate(savedInstanceState);
}
#Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
getDelegate().onPostCreate(savedInstanceState);
}
public ActionBar getSupportActionBar() {
return getDelegate().getSupportActionBar();
}
public void setSupportActionBar(#Nullable Toolbar toolbar) {
getDelegate().setSupportActionBar(toolbar);
}
#Override
public MenuInflater getMenuInflater() {
return getDelegate().getMenuInflater();
}
#Override
public void setContentView(#LayoutRes int layoutResID) {
getDelegate().setContentView(layoutResID);
}
#Override
public void setContentView(View view) {
getDelegate().setContentView(view);
}
#Override
public void setContentView(View view, ViewGroup.LayoutParams params) {
getDelegate().setContentView(view, params);
}
#Override
public void addContentView(View view, ViewGroup.LayoutParams params) {
getDelegate().addContentView(view, params);
}
#Override
protected void onPostResume() {
super.onPostResume();
getDelegate().onPostResume();
}
#Override
protected void onTitleChanged(CharSequence title, int color) {
super.onTitleChanged(title, color);
getDelegate().setTitle(title);
}
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
getDelegate().onConfigurationChanged(newConfig);
}
#Override
protected void onStop() {
super.onStop();
getDelegate().onStop();
}
#Override
protected void onDestroy() {
super.onDestroy();
getDelegate().onDestroy();
}
public void invalidateOptionsMenu() {
getDelegate().invalidateOptionsMenu();
}
private AppCompatDelegate getDelegate() {
if (mDelegate == null) {
mDelegate = AppCompatDelegate.create(this, null);
}
return mDelegate;
}
}
My pref_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:title="#string/pref_header_font_setting">
<Preference
android:summary="#string/pref_font_setting"/>
</PreferenceCategory>
<PreferenceCategory android:title="#string/pref_header_about">
<Preference
android:selectable="false"
android:summary="#string/summary_about" />
<Preference
android:summary="#string/app_version"
android:title="#string/title_version" />
</PreferenceCategory>
</PreferenceScreen>
Here you can see the project structure:
Many thanks
Andreas

Shared Preference not holding session (Android K)

I am having a project which uses Shared Preferences for Session Management. Everything is fine with the code but what really annoying is that the app is holding the session in Android Lollipop and above but unfortunately it is not holding the same for Android Kitkat and below. The session is lost whenever the app is closed and you have to lo in again. Following are the codes, I am using:
Session.java
package com.saptak.disputesession;
import android.content.Context;
import android.content.SharedPreferences;
import java.util.HashMap;
/**
* Created by Saptak Das on 27-02-2017.
*/
public class Session {
SharedPreferences sharedPreferences;
SharedPreferences.Editor editor;
Context context;
public static String KEY_FNAME="namef";
public static String KEY_LNAME="namel";
public static String IS_LOGIN;
public Session(Context context) {
this.context = context;
sharedPreferences=context.getSharedPreferences("userdetails",0);
editor=sharedPreferences.edit();
}
public void CreateLoginSession(String fname,String lname)
{
editor.putString(KEY_FNAME,fname);
editor.putString(KEY_LNAME,lname);
editor.putString(IS_LOGIN,"logged");
editor.commit();
}
public HashMap<String,String> getdetails()
{
HashMap<String,String> details=new HashMap<>();
details.put(KEY_FNAME,sharedPreferences.getString(KEY_FNAME,null));
details.put(KEY_LNAME,sharedPreferences.getString(KEY_LNAME,null));
return details;
}
public boolean loginstatus()
{
if(sharedPreferences.getString(IS_LOGIN,"unlogged").equals("logged"))
{
return true;
}
else
{
return false;
}
}
public void logoutac()
{
editor.clear();
editor.commit();
}
}
Login.java
package com.saptak.disputesession;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
/**
* Created by Saptak Das on 27-02-2017.
*/
public class Login extends Activity {
Button login;
EditText first,last;
Session session;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout);
session=new Session(getApplicationContext());
login=(Button)findViewById(R.id.log);
first=(EditText)findViewById(R.id.fname);
last=(EditText)findViewById(R.id.lname);
login.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
session.CreateLoginSession(first.getText().toString(),last.getText().toString());
startActivity(new Intent(getApplicationContext(), MainActivity.class));
finish();
}
});
}
}
MainActivity.java
package com.saptak.disputesession;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import java.util.HashMap;
public class MainActivity extends AppCompatActivity {
Session session;
Boolean flag;
TextView tf,tl;
Button logout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
session=new Session(getApplicationContext());
tf=(TextView)findViewById(R.id.xfname);
tl=(TextView)findViewById(R.id.xlname);
logout=(Button)findViewById(R.id.xlogout);
flag=session.loginstatus();
if(flag==false)
{
startActivity(new Intent(getApplicationContext(),Login.class));
finish();
}
HashMap<String,String> details=session.getdetails();
tf.setText(details.get(Session.KEY_FNAME));
tl.setText(details.get(Session.KEY_LNAME));
logout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
session.logoutac();
startActivity(new Intent(getApplicationContext(),Login.class));
finish();
}
});
}
}
This problem is getting on my nerves now as the app is perfectly coded, please help me out. Thanks in advance!
Update:
Please note, the problem is not about deleting the session, its completely opposite. The session is logging itself out everytime i am closing the app. and this problem is only in case of Android Kitkat and below, works fine for Android Lollipop and above
SharedPreferences allow you to save and retrieve data in the form of key,value pair.
Mistake
public static String IS_LOGIN="logged"; // Init here
FYI
Session are useful when you want to store user data globally through
out the application.
Rectify your method
public void CreateLoginSession(String fname,String lname)
{
editor.remove(KEY_FNAME); //Remove at first
editor.remove(KEY_LNAME);
editor.remove(IS_LOGIN);
editor.putString(KEY_FNAME,fname);
editor.putString(KEY_LNAME,lname);
editor.putString(IS_LOGIN,"logged");
editor.commit();
}

Passing from Preferences to Activity

I have one activity - Salary to which I want to pass values (numbers placed in EditTextPreference) from Preferences.
It looks like this:
ustawienia.xml:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<EditTextPreference
android:title="Przepracowane godziny"
android:key="godziny"
android:summary="Wpisz przepracowane godziny"
/>
<EditTextPreference
android:title="Stawka Godzinowa"
android:key="stawka"
android:summary="Wpisz stawkę godzinową"
/>
<EditTextPreference
android:title="ZUS"
android:key="zus"
android:summary="Wpisz wielkość składki ZUS"
/>
</PreferenceScreen>
Then Preferences class - Ustawienia.java:
package com.example.salary;
import android.os.Bundle;
import android.preference.PreferenceActivity;
public class Ustawienia extends PreferenceActivity{
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.ustawienia);
}
}
Having that I want to take values from preferences to Salary.java class to use data.
package com.example.salary;
import java.text.DecimalFormat;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class Salary extends Activity {
Button przelicz;
TextView brutto, na_czysto;
EditText netto;
SharedPreferences wez_ustawienia = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
int godziny = wez_ustawienia.getInt("godziny", 21);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_salary);
przelicz = (Button)findViewById(R.id.b_przelicz);
na_czysto = (TextView) findViewById(R.id.tv_salary);
brutto = (TextView) findViewById(R.id.tv_brutto);
netto = (EditText) findViewById(R.id.et_netto);
przelicz.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
double netto_int = Double.valueOf(netto.getText().toString());
double kasa_brutto = netto_int * 0.25 + netto_int;
DecimalFormat formatowanie = new DecimalFormat("#0.00");
kasa_brutto = Double.valueOf(formatowanie.format(kasa_brutto));
brutto.setText("Kwota brutto: \t" + kasa_brutto);
double kasa_na_czysto = (netto_int - 1000);
//DecimalFormat formatowanie = new DecimalFormat("#0.00");
kasa_na_czysto = Double.valueOf(formatowanie.format(kasa_na_czysto));
na_czysto.setText("Kwota na czysto:\t" + kasa_na_czysto);
}
});
}
#Override
public boolean onCreateOptionsMenu(android.view.Menu menu) {
// TODO Auto-generated method stub
super.onCreateOptionsMenu(menu);
MenuInflater nadmuchanie = getMenuInflater();
nadmuchanie.inflate(R.menu.menu, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch(item.getItemId()){
case R.id.oAutorze:
Intent a = new Intent("com.example.salary.OAUTORZE");
startActivity(a);
break;
case R.id.ustawienia:
Intent u = new Intent("com.example.salary.USTAWIENIA");
startActivity(u);
break;
case R.id.wyjscie:
finish();
break;
}
return false;
}
}
However the application crushes just after I added this piece of code:
SharedPreferences wez_ustawienia = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
int godziny = wez_ustawienia.getInt("godziny", 21);
What's going on with that?
Can I be caused because addPreferencesFromResource(R.xml.ustawienia); is deprecated?

How to store the seekbar values in a global variable use in another screen

Hi I am try to write a code in android where I have a 2 seekbars and I want to store the values obtained from seekbars and would like to use it in another screen. So can any help me how to do it.
I am using global variables because I want store the values untill the I store I reuse them.
Here is my code so please any one tell me how to do that.
package com.example.newairways;
import java.util.List;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.SeekBar.OnSeekBarChangeListener;
public class relationship extends Activity implements OnSeekBarChangeListener {
private String Q1a,Q1b;
private SeekBar mSeekBar1, mSeekBar2;
private TextView tv1, tv2;
private Button ok,nextQ,cancel;
private ProgressDialog dialog = null;
Intent myIntent;
//List<NameValuePair> nameValuePairs= null;
Bundle myValues;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.relationships);
myValues=getIntent().getExtras();
mSeekBar1 = (SeekBar) findViewById(R.id.Q1a);
mSeekBar1.setOnSeekBarChangeListener(this);
mSeekBar2= (SeekBar) findViewById(R.id.Q1b);
mSeekBar2.setOnSeekBarChangeListener(this);
tv1 = (TextView)findViewById(R.id.Ans1a);
tv2 = (TextView)findViewById(R.id.Ans1b);
TextView welcomeMsg = (TextView)findViewById(R.id.username);
welcomeMsg.setText("name : "+myValues.getString("value"));
ok = (Button)findViewById(R.id.ok);
nextQ = (Button)findViewById(R.id.nextquestion);
cancel= (Button)findViewById(R.id.cancel);
}
#Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
switch (seekBar.getId())
{
case R.id.Q1a:
tv1.setText(Integer.toString(progress)+"%") ;
Toast.makeText(relationship.this, "Seekbar Value : " + progress, Toast.LENGTH_SHORT).show();
break;
case R.id.Q1b:
tv2.setText(Integer.toString(progress)+"%") ;
Toast.makeText(relationship.this, "Seekbar Value : " + progress, Toast.LENGTH_SHORT).show();
break;
}
}
#Override
public void onStartTrackingTouch(SeekBar arg0) {
// TODO Auto-generated method stub
}
#Override
public void onStopTrackingTouch(SeekBar arg0) {
// TODO Auto-generated method stub
}
}
Create a file GlobalVars.java:
public class GlobalVars extends Application {
private static String value2;
public static String getSeekBarValue() {
return value2;
}
public static void setSeekBarValue(String value) {
value2 = value;
}
}
Then in your files you can save and load your variables:
GlobalVars.setSeekBarValue(progress);
int v = GlobalVars.getSeekBarValue();
You asked for global variables but don't forget that the values they store are deleted every time you exit the app.

when don't keep activities selected on Setting , progress dialog is not dismissing

when "don't keep activities" is selected on Setting's Developer Options progress dialog is not dismissing.
Actually, I am displaying the Progerss bar,for initialize the Application, When I am going to Activity A to Activity B and then came to Activity A, the Progress bar is not dismissing after initialize completed.
Below is my Code,
First Activity
package com.example.donotkeepactivitiesalive;
import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
public static final int MESSAGE_PROGRESS_BAR_INITIALIZING = 1;
private Dialog m_cObjDialog;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
System.out.println(getClass().getName() + "before InitializeEnvironment >>>>>>");
new InitializeEnvironment().execute();
System.out.println(getClass().getName() + "after InitializeEnvironment >>>>>>");
Button lb = (Button) findViewById(R.id.button1);
lb.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent lIntent = new Intent(MainActivity.this, SecondActivity.class);
startActivity(lIntent);
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
#Override
protected Dialog onCreateDialog(int id) {
m_cObjDialog = new ProgressDialog(this);
m_cObjDialog.setTitle("Initializing");
((ProgressDialog) m_cObjDialog).setMessage("Initializing the Application");
m_cObjDialog.setCancelable(false);
return m_cObjDialog;
}
class InitializeEnvironment extends AsyncTask<String, String, String> {
#Override
protected void onPreExecute() {
System.out.println(getClass().getName() + "onPreExecute >>>>>>");
super.onPreExecute();
showDialog(MESSAGE_PROGRESS_BAR_INITIALIZING);
}
#Override
protected String doInBackground(String... aurl) {
System.out.println(getClass().getName() + " doInBackground >>>>>>");
return null;
}
#Override
protected void onPostExecute(String unused) {
dismissDialog(MESSAGE_PROGRESS_BAR_INITIALIZING);
System.out.println(getClass().getName() + " onPostExecute >>>>>>");
}
}
}
Second Activity
package com.example.donotkeepactivitiesalive;
import android.app.Activity;
import android.os.Bundle;
public class SecondActivity extends Activity{
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Is there any way to track this problem and work even if "don't keep activities" is enabled
I solved this, by checking the Bundle object is null or not.If the Bundle object is null then call the AsynTask class, else don't call,
if(null == savedInstanceState) {
new InitializeEnvironment().execute();
}
But make sure that your previous Activity is not overriding onActivityResult()

Categories

Resources