Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9213439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:45:00+00:00 2026-06-18T01:45:00+00:00

I have made an application in that i have an activity contains a TextView

  • 0

I have made an application in that i have an activity contains a TextView and a button.Now this activity is used multiple times in the application so i want is that when i click the back button in that activity ,it should go to the previous activity.In short it should work as back button of device.My code is as below:

this activity is used in 4 activities ,

So i have tried as below:

Advance_help.java

package com.theappgeeks.kevingreenwealth;

import java.text.BreakIterator;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class AdvanceHelp extends Activity implements OnClickListener{
Button btn;
Calculator_1Activity cal1 =new Calculator_1Activity();
Calculator2 cal2 =new Calculator2();
Calculator_3Activity cal3 =new Calculator_3Activity();
Calculator_4Activity cal4 =new Calculator_4Activity();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_advance_help);
        btn=(Button)findViewById(R.id.button1);
        /*btn.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                if(btn.)
            Intent i1=new Intent(AdvanceHelp.this,Calculator_1Activity.class);  
            startActivity(i1);

            }
        });*/
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_advance_help, menu);
        return true;
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        if(v.equals(cal1)){
            btn.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    Intent i1= new Intent(AdvanceHelp.this,Calculator_1Activity.class);
                    startActivity(i1);
                }

            });

        }
        else if(v.equals(cal2)){
            btn.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    Intent i1= new Intent(AdvanceHelp.this,Calculator2.class);
                    startActivity(i1);
                }

            });

        }

        else if(v.equals(cal3)){
            btn.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    Intent i1= new Intent(AdvanceHelp.this,Calculator2.class);
                    startActivity(i1);
                }

            });

        }

        else if(v.equals(cal4)){
            btn.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    Intent i1= new Intent(AdvanceHelp.this,Calculator2.class);
                    startActivity(i1);
                }

            });

        }
        else
        {
            Intent i = new Intent(AdvanceHelp.this,MainMenuActivity.class);
            startActivity(i);
        }
    }
}

Please help me as soon as possible..thank you
in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T01:45:01+00:00Added an answer on June 18, 2026 at 1:45 am

    Bad programming practice,

    As you already implements OnClickListener

    btn=(Button)findViewById(R.id.button1);
    btn.setOnClickListener(this);
    

    and remove

     btn.setOnClickListener(new OnClickListener() {
    

    from

    @Override
        public void onClick(View v) {
    

    And for

    i want is that when i click the back button in that activity ,it should go to the previous
    activity.In short it should work as back button of device.My code is as below:
    

    Just call Activity’s finish() in button’s click() on which you want..

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on an android application. I have an activity that contains a
I have made an application now i want to implement Rate Us feature in
I have made a bottom tab bar in the application.What I want is that
I have made an application that gives the user the option to open up
I have made a web application that uses master page for Login & Logout
I have made a java application that stores data from a .csv file to
I have made an application in android that lets the user compress and decompress
I have made a view in the application that shows a UITableView. It will
I have made a build system for my web application that's rewriting all resource
I need to run the application that I have made in Xcode on my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.