AsyncOp

A very helpful framework for asynchronous operation related to an Activity or Fragment for Android application

License

License

Categories

Categories

GUI User Interface
GroupId

GroupId

com.github.mguidi.asyncop
ArtifactId

ArtifactId

asyncop
Last Version

Last Version

1.1.0
Release Date

Release Date

Type

Type

aar
Description

Description

AsyncOp
A very helpful framework for asynchronous operation related to an Activity or Fragment for Android application
Project URL

Project URL

https://github.com/mguidi/asyncop
Source Code Management

Source Code Management

https://github.com/mguidi/asyncop

Download asyncop

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.mguidi.asyncop/asyncop/ -->
<dependency>
    <groupId>com.github.mguidi.asyncop</groupId>
    <artifactId>asyncop</artifactId>
    <version>1.1.0</version>
    <type>aar</type>
</dependency>
// https://jarcasting.com/artifacts/com.github.mguidi.asyncop/asyncop/
implementation 'com.github.mguidi.asyncop:asyncop:1.1.0'
// https://jarcasting.com/artifacts/com.github.mguidi.asyncop/asyncop/
implementation ("com.github.mguidi.asyncop:asyncop:1.1.0")
'com.github.mguidi.asyncop:asyncop:aar:1.1.0'
<dependency org="com.github.mguidi.asyncop" name="asyncop" rev="1.1.0">
  <artifact name="asyncop" type="aar" />
</dependency>
@Grapes(
@Grab(group='com.github.mguidi.asyncop', module='asyncop', version='1.1.0')
)
libraryDependencies += "com.github.mguidi.asyncop" % "asyncop" % "1.1.0"
[com.github.mguidi.asyncop/asyncop "1.1.0"]

Dependencies

compile (1)

Group / Artifact Type Version
com.android.support » support-v4 jar 21.0.0

Project Modules

There are no modules declared in this project.

asyncop

A very helpful framework for asynchronous operation related to an Activity or Fragment for Android application

How to use

With Android Studio add dependency:

compile 'com.github.mguidi.asyncop:asyncop:1.0.0'

Define your async operation extending the AsyncOp Class:

public class LongOp extends AsyncOp {

	@Override
    public Bundle execute(Context context, Bundle args) {
    
	    Bundle result = new Bundle();
    
    	// define your operation here

        return result;
	}

}

Map your operation with an action in your Application class:

public class Application extends android.app.Application {

	@Override
    public void onCreate() {
	    super.onCreate();

    	AsyncOpManager.getInstance(this).mapOp("long_op", LongOp.class);
	}
}

Execute the operation inside an Activity or a Fragment

public class MyActivity extends ActionBarActivity implements AsyncOpCallback, View.OnClickListener {

    private AsyncOpHelper mOpHelper;

	@Override
    protected void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
    	setContentView(R.layout.activity_my);

		// initialize the Async op helper on the onCreate
        mOpHelper = new AsyncOpHelper(this, savedInstanceState, this);

	    findViewById(R.id.btnHello).setOnClickListener(this);
	}

    @Override
	protected void onResume() {
    	super.onResume();
        mOpHelper.onResume();
	}

    @Override
	protected void onSaveInstanceState(Bundle outState) {
    	super.onSaveInstanceState(outState);
        mOpHelper.onSaveInstanceState(outState);
	}

    @Override
	protected void onPause() {
    	super.onPause();
        mOpHelper.onPause();
	}

    @Override
	public void onAsyncOpFinish(int idRequest, String action, Bundle args, Bundle result) {
    	if (action.equals("long_op")) {

			// handle the result here

    	}
    }

	@Override
    public void onAsyncOpFail(int idRequest, String action) {
    	if (action.equals("long_op")) {
        	
        	// hadle the operaion fail here
        	// the onAscynOpFail is called only in the case that your async op was running when the system killed it
        	
        }
	}

    @Override
	public void onClick(View v) {
    	if (v.getId() == R.id.btnHello) {

			// define a bundle with the async op params
        	Bundle args = new Bundle();
        	
			// execute the async op mapped with the action
			mOpHelper.execute("long_op", args);
    	}
	}
}

Versions

Version
1.1.0
1.0.0