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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:01:32+00:00 2026-05-27T03:01:32+00:00

So I want to use a button to lead over to a new activity

  • 0

So I want to use a button to lead over to a new activity that can pick between two ints(hours and mins) rather than setting an alarm. Or maybe do something different to access the value of those ints and change them? Is there a better way to code that?

My code so far is this – am I doing it right so far?

public class AlarmPtest extends Activity implements  android.view.View.OnClickListener{
/** Called when the activity is first created. */

Button SetAlarm, SetTimer;
int hours = 1, min = 30;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Vars();

}


private void AlarmClock() {
    // TODO Auto-generated method stub
    Intent i = new Intent(android.provider.AlarmClock.ACTION_SET_ALARM);
    i.putExtra(android.provider.AlarmClock.EXTRA_HOUR, hours);
    i.putExtra(android.provider.AlarmClock.EXTRA_MINUTES, min);
    startActivity(i);

}


private void Vars() {
    // TODO Auto-generated method stub
    SetAlarm = (Button) findViewById(R.id.SetAlarm);
    SetTimer = (Button) findViewById(R.id.TimerAlarm);

    SetAlarm.setOnClickListener(this);
    SetTimer.setOnClickListener(this);
}


public void onClick(View v) {
    // TODO Auto-generated method stub
    switch (v.getId()){
    case R.id.SetAlarm:
        Toast alarmToast = Toast.makeText(this, "you click alarm", Toast.LENGTH_LONG);
        alarmToast.show();
        AlarmClock();
     case R.id.TimerAlarm:
        Toast TimerToast = Toast.makeText(this, "you get 15 min", Toast.LENGTH_LONG);
        TimerToast.show();
        hours = 0 ;
        min = 15;
        AlarmClock();
    }
}

}

  • 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-27T03:01:32+00:00Added an answer on May 27, 2026 at 3:01 am

    Your code is right, in the sense that your hours and mins will be pased in the alarm intent. And the alarm will be set if the user has Android SDK >= 9

    BTW a common code convention in Java and thus Android, is to write function names starting with smallLetters. Hence, change your functions to:

    private void alarmClock()
    private void vars()
    

    Otherwise, people might get the impression your referring to a Class. The same convention is used for variable names, so you will want to change your buttons as well:

    Button setAlarm, setTimer;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array of strings that I want to use for button titles
I want to use jquery ui button for buttons created in future. can i
I want to use button that background image is mine and text is on
I want to use the button style on another control. How can I call
I want to use some kind of trigger to change a button in my
I have a button I want to use in the beginning and the end
customers does not want to allow user to use back or forward button. Just
I want to lock back button while my data process. I use AsyncTask to
I want use BYTE_ORDER macro in my Xcode project but i can't because i
I want to use a button which when the mouse enters the button a

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.