java - 如何从新 Activity 返回主抽屉导航 Activity

标签 java android android-fragments android-activity

首先我创建了 Navigation Drawer Activity 的应用程序并从 fragment 移动到新 Activity ,现在我想在导航到抽屉导航的主要 Activity 的新 Activity 上设置主页按钮。 但是当我从应用程序运行它时,单击主页按钮时它会给我这个 firts

但我想直接进入 MainActivity 这里 enter image description here

新 Activity .java

package com.shubham.navi_demo;

import android.content.Intent;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;

public class NewActivity extends FragmentActivity {

private static Button Button;

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

public void onclickbutton(){
    Button = (Button)findViewById(R.id.button);
    Button.setOnClickListener(
            new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent("android.intent.action.MAIN");
                    startActivity(intent);
                }
            }
    );
 }
}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".NewActivity">
        <intent-filter>
            <action android:name="com.shubham.navi_demo.NewActivity" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
</application>

</manifest>

最佳答案

您不必使用 Intent 启动 activity。只需在 NewActivity 中调用 finish(),它就会向您显示 Main Navigation drawer Activity

希望这对您有所帮助。

关于java - 如何从新 Activity 返回主抽屉导航 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35124169/

相关文章:

java - 如何将用户提供的数据传递给下一个 Activity

Java正则表达式模式匹配

android - 带有 UTF8 文本的 POST 以 ASCII 形式出现

android - NestedScrolling 在 BottomSheetDialog 内的 Viewpager 内

android在fragment上实现寻呼机时出错

java - 从 Java 调用 SQL 包过程

java - DSL 选择中的 JOOQ 和 PostgreSQL 类型

android - LocationServices getFusedLocationProviderClient无法正常工作

android - 清除适配器然后添加项目,修复错误

android - 列出项目点击监听器上的 fragment