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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:27:56+00:00 2026-06-04T17:27:56+00:00

I have made a simple Android program. What it does: On startup it shows

  • 0

I have made a simple Android program.

What it does:
On startup it shows a text and a button. On the button is a number that increases every time its touched. At a random number on the button between 2 and 10, a picture shows up + a ssoundclip.

This is what it do. So when it shows the picture the app is finish.

What i want to do now is to create a touch function that directs me back to the apps startup page. For that i need your help. I have tried searching the internet for a solution, but since im a beginner at this i cant figure how to implement it in my code.

Here is my code:

package net.ibasic;

import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class HelloAndroidActivity extends Activity implements OnClickListener {
private int i = 0;
public int low = 2;
public int high = 10;
public int num = low + (int) ( Math.random()*(high -low) + 0.5 );
MediaPlayer mpAudio;
MediaPlayer mpAudio1;
/** Called when the activity is first created. */ 
@Override

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //setContentView(R.layout.main);
    //creating the setContentView by java-code instead of Xml
    LinearLayout linearLayout = new LinearLayout(this);
    linearLayout.setOrientation(LinearLayout.VERTICAL);

    TextView textView = new TextView(this);
    textView.setText(R.string.hello);

    linearLayout.addView(textView);

    //creating a button for the app
    Button button = new Button(this);
    linearLayout.addView(button);

    setContentView(linearLayout);
    update(button);

    //adding buttonListener
    button.setOnClickListener(this);
    mpAudio = MediaPlayer.create(this, R.raw.kitten);
    mpAudio1 = MediaPlayer.create(this, R.raw.scary);
}



private void update(Button button) {
    button.setText("Amount of Clicks " + i++);

}

public void onClick(View button) {
    update((Button)button);

    if (i==num){

        LinearLayout linearLayout = new LinearLayout(this);
        linearLayout.setOrientation(LinearLayout.VERTICAL);

        if (num % 2 == 0){
        mpAudio.start();
        ImageView imageView = new ImageView(this);
        imageView.setImageResource(R.drawable.kitten);

        TextView textView1 = new TextView(this);
        textView1.setText(R.string.kittentext);
        linearLayout.addView(textView1);
        linearLayout.addView(imageView);

        }
        else{
            mpAudio1.start();
            ImageView imageView = new ImageView(this);
            imageView.setImageResource(R.drawable.scary);

            TextView textView1 = new TextView(this);
            textView1.setText(R.string.scarytext);
            linearLayout.addView(textView1);
            linearLayout.addView(imageView);

        }




        setContentView(linearLayout);
    }
}
}
  • 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-04T17:27:57+00:00Added an answer on June 4, 2026 at 5:27 pm

    After you are done use the following code to restart your activity:

    Intent intent = getIntent();
    finish();
    startActivity(intent); //
    

    Reference


    You can do this on the click of a button/ can also automate the button click using performClick() method on button object or whenever you want.

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

Sidebar

Related Questions

I have made a few simple apps on android, and thought it was time
I've made a simple Android music player. I want to have a TextView that
I have made my own file type (.ddd) and I made a simple program
I have started using jQuery and rails. I have made a simple form that
I have made a program that list all files and folders(f&f) locating on sd
I am trying to create a simple 3-D app for android that will have
So I have a simple Edit-text with number input. User enters his phone number
I made a simple extension of CheckBoxPreference so that I could have my own
I'm just beginning Android and have gotten myself stuck. I've made a simple app/view.
I am android newbie. I made a simple program, and I used Toast code

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.