Last active
September 30, 2015 07:48
-
-
Save up1/1628bdaecffe5e9b8339 to your computer and use it in GitHub Desktop.
Android :: send data in application
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<application | |
android:name="com.devahead.extendingandroidapplication.MyApplication"> | |
... | |
... | |
</application> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MyApplication app = (MyApplication) getApplication(); | |
String data = app.getData(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); | |
boolean value = settings.getBoolean("key", false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyApplication extends Application { | |
private String data; | |
public String getData() { | |
return data; | |
} | |
public void setData(String data) { | |
this.data = data; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Bundle bundle = getIntent().getExtras(); | |
String value = bundle.getString("key"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Intent intent = new Intent(FirstActivity.this, SecondActivity.class); | |
intent.putExtra("key", value); | |
startActivity(intent); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MyApplication app = (MyApplication) getApplication(); | |
app.setData(someData); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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