android桌面快捷方式跳转到指定activity

本文介绍如何在Android应用中配置AndroidManifest.xml,创建桌面快捷方式,实现直接跳转到指定的Activity。通过这种方法,用户可以快速启动应用内的特定功能。
摘要由CSDN通过智能技术生成

AndroidManifest.xml 应用主入口配置:

        <activity
            android:name="com.*.cust.contacts.MainActivity"
            android:exported="true"
            android:label="@string/app_name"
            android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <!-- 自定义的action,通过自定义的action可以应用内调用 -->
                <action android:name="*.intent.action.SHORTCUT" />

                <category android:name="android.intent.category.LAUNCHER" />
                <!-- 必须加上这个,否则无法直接使用自定的action -->
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

创建快捷方式:

好的,下面是一个简单的实现登录并跳转到其他Activity的示例代码: 1. 在布局文件中添加登录界面的控件,例如EditText和Button。 ```xml <EditText android:id="@+id/et_username" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="请输入用户名"/> <EditText android:id="@+id/et_password" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="请输入密码"/> <Button android:id="@+id/btn_login" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="登录"/> ``` 2. 在Activity的Java文件中,获取登录界面的控件,并设置登录按钮的点击事件,实现登录验证和跳转到其他Activity的功能。 ```java public class LoginActivity extends AppCompatActivity { private EditText etUsername, etPassword; private Button btnLogin; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); etUsername = findViewById(R.id.et_username); etPassword = findViewById(R.id.et_password); btnLogin = findViewById(R.id.btn_login); btnLogin.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // 获取输入的用户名和密码 String username = etUsername.getText().toString().trim(); String password = etPassword.getText().toString().trim(); // 进行登录验证,这里只是一个简单的示例 if (username.equals("admin") && password.equals("123456")) { // 登录成功,跳转到其他Activity Intent intent = new Intent(LoginActivity.this, OtherActivity.class); startActivity(intent); } else { // 登录失败,弹出提示框 Toast.makeText(LoginActivity.this, "用户名或密码错误", Toast.LENGTH_SHORT).show(); } } }); } } ``` 以上是一个简单的实现登录并跳转到其他Activity的示例代码,你可以根据自己的需求进行修改和完善。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值