Skip to content

Instantly share code, notes, and snippets.

@up1
Last active September 30, 2015 07:48
Show Gist options
  • Save up1/1628bdaecffe5e9b8339 to your computer and use it in GitHub Desktop.
Save up1/1628bdaecffe5e9b8339 to your computer and use it in GitHub Desktop.
Android :: send data in application
<application
android:name="com.devahead.extendingandroidapplication.MyApplication">
...
...
</application>
MyApplication app = (MyApplication) getApplication();
String data = app.getData();
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
boolean value = settings.getBoolean("key", false);
public class MyApplication extends Application {
private String data;
public String getData() {
return data;
}
public void setData(String data) {
this.data = data;
}
}
Bundle bundle = getIntent().getExtras();
String value = bundle.getString("key");
Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
intent.putExtra("key", value);
startActivity(intent);
MyApplication app = (MyApplication) getApplication();
app.setData(someData);
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("key", value);
editor.commit();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment