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 7693037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:59:27+00:00 2026-05-31T20:59:27+00:00

After trying a lot i decided to ask question on stackoverflow, I create a

  • 0

After trying a lot i decided to ask question on stackoverflow, I create a class for using on button click and start an intent from this class.

import android.app.Activity;
import android.content.Intent;
import android.view.View;

public class OnClickListener implements android.view.View.OnClickListener{

    Activity current;
    Object goTo;

    public OnClickListener(Activity arg0, Activity arg1){
        this.current = arg0;
        this.goTo = arg1;
    }

    @Override
    public void onClick(View v) {
        Intent intent = new Intent(current, goTo.getClass());
        current.startActivity(intent);
    }

}

and passing parameter like this:

Button button = (Button)findViewById(R.id.class2_btn);
        Class2 class2 = new Class2();
        OnClickListener listener = new OnClickListener(class1.this, class2);
        button.setOnClickListener(listener);

why this is not working? after clicking button why this is not going to next class?
Please help me.

  • 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-05-31T20:59:29+00:00Added an answer on May 31, 2026 at 8:59 pm

    There are some points i want to figure out here :

    1. As you are using startActivty(), as the name suggests it is for activity not for simple class as you are trying here.Activity is like an UI that you can start but simple class is like a Model class they are not going start like activity.
    2. If you will using activity in place of class then it will defiitely work.In that case you do not need to pass any argument just you can give name directly like below:

    Intent intent = new Intent(current_activity.this, target_activty.class);
    current.startActivity(intent);

    1. If you class2 is an activity then you should give it directly to startActivty() as i sated in above point not it’s object like you did.And also ass this activity into menifest file.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I finally decided to post a question here after some time spent trying to
I'm trying to reorder UITableView in iOS application. After harvesting a lot of StackOverFlow
We've been trying to alter a lot of columns from nullable to not nullable,
After trying to avoid JavaScript for years, Iv started using Query for validation in
After spending a lot of time trying to wrap my head around multiprocessing I
After trying to setup my site for Google Webmaster Tools I found that my
After trying to understand why client code is not rendered in a page (injected
After trying to make a while(bool) loop and it failing because I couldn't see
After trying my hand at Perl and a little bit of C, I am
After trying out VS2010b2 also my VS2008 installation changes the versions of solution and

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.