找到你要的答案

Q:How can I return Home activity from child activity?

Q:我怎样才能从儿童活动中返回家庭活动?

This is my code, I want to go to Home activity by clicking app icon button. My same code works fine for HomeActivity button .

package com.coderbd.englishtutor;

import android.app.Activity;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;


public class StudyActivity extends Activity implements OnClickListener{

Button app_icon_topBar;
ImageButton reset;
ImageButton settings;
ImageButton share;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_study);
    app_icon_topBar=(Button) findViewById(R.id.app_icon_topBar);
    reset=(ImageButton) findViewById(R.id.btn_Reset);
    settings=(ImageButton) findViewById(R.id.btn_Settings);
    share=(ImageButton) findViewById(R.id.btn_Share);

    app_icon_topBar.setOnClickListener(this);
    reset.setOnClickListener(this);
    settings.setOnClickListener(this);
    share.setOnClickListener(this);
}

public void onClick(View v) {

    switch(v.getId()){
    case R.id.app_icon_topBar:
        finish();
        setContentView(R.layout.another_home_activity);
        break;
    case R.id.btn_Reset:
        finish();
        setContentView(R.layout.activity_contact);
        break;
    case R.id.btn_Settings:
        finish();
        setContentView(R.layout.activity_help);
        break;
    case R.id.btn_Share:
        finish();
        setContentView(R.layout.activity_scores);
        break;
    default:
        finish();
        setContentView(R.layout.another_home_activity);
        break;  
    }
}

Please help me. Advance Thanks.

这是我的代码,我想通过点击按钮来进入家庭活动按钮。我工作的很好的homeactivity按钮相同的代码。

package com.coderbd.englishtutor;

import android.app.Activity;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;


public class StudyActivity extends Activity implements OnClickListener{

Button app_icon_topBar;
ImageButton reset;
ImageButton settings;
ImageButton share;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_study);
    app_icon_topBar=(Button) findViewById(R.id.app_icon_topBar);
    reset=(ImageButton) findViewById(R.id.btn_Reset);
    settings=(ImageButton) findViewById(R.id.btn_Settings);
    share=(ImageButton) findViewById(R.id.btn_Share);

    app_icon_topBar.setOnClickListener(this);
    reset.setOnClickListener(this);
    settings.setOnClickListener(this);
    share.setOnClickListener(this);
}

public void onClick(View v) {

    switch(v.getId()){
    case R.id.app_icon_topBar:
        finish();
        setContentView(R.layout.another_home_activity);
        break;
    case R.id.btn_Reset:
        finish();
        setContentView(R.layout.activity_contact);
        break;
    case R.id.btn_Settings:
        finish();
        setContentView(R.layout.activity_help);
        break;
    case R.id.btn_Share:
        finish();
        setContentView(R.layout.activity_scores);
        break;
    default:
        finish();
        setContentView(R.layout.another_home_activity);
        break;  
    }
}

请帮助我。提前谢谢。

answer1: 回答1:

Put this in your app icon button's onClick:

case R.id.app_icon_topBar:
    Intent intent = new Intent(StudyActivity.this, HomeActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(intent);
    break;

把这个放在你的应用程序图标按钮的onclick:

case R.id.app_icon_topBar:
    Intent intent = new Intent(StudyActivity.this, HomeActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(intent);
    break;
android  return  home