一對一聊天軟體原始碼,實現各個子介面跳轉和傳參

zhibo系統開發發表於2021-11-17

一對一聊天軟體原始碼,實現各個子介面跳轉和傳參的相關程式碼

1新增依賴

javaCompileOptions {
            annotationProcessorOptions {
                arguments = [moduleName :project.getName() ]
            } }
    compile'com.alibaba:arouter-api:1.3.1'
    annotationProcessor'com.alibaba:arouter-compiler:1.1.4'

2起始activity

package com.example.arouter;
import android.os.Bundle;
import android.view.View;
import androidx.appcompat.app.AppCompatActivity;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.example.myapplication.R;
@Route(path = "/app/ArouterActivity")
public class ArouterActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_arouter);
        ARouter.getInstance().inject(this);
    }
    public void go(View view) {
        ARouter.getInstance().build(Constance.DeatailActivityURL)
                .withString("name","wy")
                .withInt("age",6)
                .navigation();
    }
}

3目標activity

package com.example.arouter;
import android.os.Bundle;
import android.util.Log;
import androidx.appcompat.app.AppCompatActivity;
import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.example.myapplication.R;
@Route(path = Constance.DeatailActivityURL)
public class ArouterDetailActivity extends AppCompatActivity {
    @Autowired
    public String name;
    @Autowired
    public int age;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_arouter_detail);
        ARouter.getInstance().inject(this);
        Log.e("wy", "onCreate: "+name+" age:"+age );
    }
}

4url池塘

package com.example.arouter;
public class Constance {
    public static final String DeatailActivityURL="/app/ArouterDetailActivity";
}

以上就是 一對一聊天軟體原始碼,實現各個子介面跳轉和傳參的相關程式碼,更多內容歡迎關注之後的文章


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69978258/viewspace-2842640/,如需轉載,請註明出處,否則將追究法律責任。

相關文章