Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nuuneoi/StatedFragment
Deprecated
https://github.com/nuuneoi/StatedFragment
Last synced: 3 months ago
JSON representation
Deprecated
- Host: GitHub
- URL: https://github.com/nuuneoi/StatedFragment
- Owner: nuuneoi
- Archived: true
- Created: 2015-03-05T14:15:52.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-04-27T08:09:21.000Z (over 9 years ago)
- Last Synced: 2024-07-01T10:53:31.314Z (4 months ago)
- Language: Java
- Homepage:
- Size: 336 KB
- Stars: 473
- Watchers: 16
- Forks: 84
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-StatedFragment-brightgreen.svg?style=flat)](http://android-arsenal.com/details/1/1660)
# StatedFragment
Provides a functionality to retrieve `onActivityResult` in nested fragment.
# Version
0.10.0
# Installation
To use this library in your android project, just simply add the following dependency into your build.gradle
StatedFragment for Android Support Library v4's Fragment
```sh
dependencies {
compile 'com.inthecheesefactory.thecheeselibrary:stated-fragment-support-v4:0.10.0'
}
```StatedFragment for Android's Fragment
```sh
dependencies {
compile 'com.inthecheesefactory.thecheeselibrary:stated-fragment:0.10.0'
}
```# Usage
### onActivityResult for Nested Fragment
In **v0.10.0** onward, `NestedActivityResultFragment` is introduced to fix `onActivityResult` problem which couldn't be called on nested fragment. To use it, you have to override `onActivityResult` on your `Activity` and add a line of code:
```java
@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
super.onActivityResult(requestCode, resultCode, data);
ActivityResultBus.getInstance().postQueue(new ActivityResultEvent(requestCode, resultCode, data));
}
```And in your fragment, you need to call `getActivity().startActivityForResult(...)` but not `startActivityForResult(...)` since we need to let all the result sent to Activity.
Lastly, override `onActivityResult` in your fragment in the standard way.
```java
public class MainFragment extends NestedActivityResultFragment {
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Add your code here
Toast.makeText(getActivity(), "Fragment Got it: " + requestCode + ", " + resultCode, Toast.LENGTH_SHORT).show();
}
}
```### State Saving/Restoring
Since v0.10.0, `StatedFragment` is now marked **deprecated**. Please use the traditional way documented at http://inthecheesefactory.com/blog/fragment-state-saving-best-practices/en instead
# Change Logs
### v0.10.0
- `StatedFragment` is marked **deprecated**. Traditional way to save/restore fragment's state is recommended.
- `NestedActivityResultFragment` is introduced to fix `onActivityResult` problem which couldn't be called on nested fragment### v0.9.3
Add support to `` tag.
### v0.9.2
Add onActivityResult feature for nested fragment.
### v0.9.1
Change Android Support Library v4 dependency's version to 21.+ to avoid future dependency conflict.
### v0.9.0
Seperates library into two versions:
- stated-fragment-support-v4: Fragment is inherited from android.support.v4.app.fragment
- stated-fragment: Fragment is inherited from android.app.fragment# License
Apache 2.0