Skip to content

A solution to make it easy to launch an activity with parameters.

Notifications You must be signed in to change notification settings

cooper-zhou/ActivityLauncher

Repository files navigation

ActivityLauncher

A solution to make it easy to launch an activity with parameters.

Example

  1. An activity launcher can be define by the @Launcher annotation, and the @Required annotation means the parameter has to be delivered when launching this activity. On the contrary, the @Optiinal annotation means the parameter can be delivered or not:
@Launcher(
        flags = {Intent.FLAG_ACTIVITY_CLEAR_TOP},
        pendingTransition = R.anim.anim_slide_right_in,
        pendingTransitionOnFinish = R.anim.anim_slide_left_out
)
public class UserInfoActivity extends AppCompatActivity {

    @Required int userId;
    
    @Optional boolean isEdit;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);
        ActivityLauncher.fill(this, savedInstanceState);
    }
}
  1. And that is how you launch the activity:
UserInfoActivityLauncher.builder(userId)
                        .isEdit(true)
                        .start(context);
  1. Also, you can use the @OnActivityResult annotation to handle the activity result calling:
public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);
        
        UserInfoActivityLauncher.builder(userId)
                        .isEdit(true)
                        .startForResult(context, requestCode);
    }
    
    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        ActivityLauncher.dispatchResult(this, requestCode, resultCode, data);
    }
    
    @OnActivityResult(requestCode = 1, resultCode = RESULT_OK)
    public void handleTakePhoto(Intent data) {
        // TODO: do something.
    }
}

Install

1 Add the repository address in builde.gradle(Project) file:

allprojects {
    repositories {
        maven {
            url uri('https://raw.githubusercontent.com/cooperise/ActivityLauncher/master/repo')
        }
    }
}

2 To compile file in builde.gradle(Module) file:

implementation 'cn.cooper.support:activitylauncher:1.0.0'
annotationProcessor 'cn.cooper.support:activitylauncher-compiler:1.0.0'

About

A solution to make it easy to launch an activity with parameters.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages