launch

替换startActivity,可以在任意地方打开Activity和处理onActivityResult

License

License

GroupId

GroupId

io.github.bin0801
ArtifactId

ArtifactId

launch
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

aar
Description

Description

launch
替换startActivity,可以在任意地方打开Activity和处理onActivityResult
Project URL

Project URL

https://github.com/bin0801/launch
Source Code Management

Source Code Management

https://github.com/bin0801/launch

Download launch

How to add to project

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

Dependencies

compile (1)

Group / Artifact Type Version
androidx.appcompat » appcompat jar 1.1.0

Project Modules

There are no modules declared in this project.

简介

替换startActivity,可以在任意地方打开Activity和处理onActivityResult

implementation 'io.github.bin0801:launch:1.0.0'

使用方式:

Activity继承LaunchActivity,使用launchForResult打开Activity

public class MainActivity extends LaunchActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        findViewById(R.id.tv_click1).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, DemoActivity.class);
                intent.putExtra("key", "launchForResult");
                launchForResult(intent, new LaunchCallback() {
                    @Override
                    public void onCallback(int resultCode, Intent intent) {
                        Toast.makeText(MainActivity.this, "resultCode : " + resultCode + " intent : " + intent, Toast.LENGTH_SHORT).show();
                    }
                });
            }
        });
    }
}

工具类打开Activity,Activity可继承可不继承LaunchActivity(强烈建议继承LaunchActivity,性能更优),使用LaunchTools.launchForResult打开Activity(只需要Context)

public class MainActivity extends LaunchActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        findViewById(R.id.tv_click2).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, DemoActivity.class);
                intent.putExtra("key", "LaunchTools.launchForResult(context = Activity)");
                LaunchTools.launchForResult(MainActivity.this, intent, new LaunchCallback() {
                    @Override
                    public void onCallback(int resultCode, Intent intent) {
                        Toast.makeText(MainActivity.this, "resultCode : " + resultCode + " intent : " + intent, Toast.LENGTH_SHORT).show();
                    }
                });
            }
        });
        findViewById(R.id.tv_click3).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                final Context context = MainActivity.this.getApplicationContext();
                Intent intent = new Intent(context, DemoActivity.class);
                intent.putExtra("key", "LaunchTools.launchForResult(context = application)");
                LaunchTools.launchForResult(context, intent, new LaunchCallback() {
                    @Override
                    public void onCallback(int resultCode, Intent intent) {
                        Toast.makeText(context, "resultCode : " + resultCode + " intent : " + intent, Toast.LENGTH_SHORT).show();
                    }
                });
            }
        });
    }
}

Versions

Version
1.0.0