This time the task is two people to design a simple app, which design to the source code design, source code implementation and source code control. Before we designed the app, we looked at how the software was designed and implemented, and then we decided to make a simple app-reminder of the small alarm clock. In the design process, a lot of problems, because never designed the app, began to completely do not know how to design code, we two discussed under, in Baidu found a tutorial, followed by a tutorial step after study how to design an app. We think to make a reminder small alarm clock app, its function is the user set up the time and things, the app will be set by the user time, and then show the user before the input.
Code we refer to some information and other design code, the final core code is as follows
Package com.example.alarmtest;
Import Java.util.Calendar;
Import android.app.Activity;
Import Android.app.AlarmManager;
Import android.app.PendingIntent;
Import Android.app.Service;
Import Android.app.TimePickerDialog;
Import android.content.Intent;
Import Android.os.Bundle;
Import Android.view.View;
Import Android.view.View.OnClickListener;
Import Android.widget.Button;
Import Android.widget.TimePicker;
Import Android.widget.Toast;
public class Mainactivity extends Activity {
Button button;
Alarmmanager Alarmmanager;
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
Button = (button) Findviewbyid (R.id.button1);
Get Alarmmanager Object
Alarmmanager = (Alarmmanager) getsystemservice (Service.alarm_service);
Button.setonclicklistener (New Onclicklistener () {
@Override
public void OnClick (View arg0) {
Calendar currenttime = Calendar.getinstance ();
Creates a Timepickerdialog instance and displays
New Timepickerdialog (mainactivity.this, 0,
New Timepickerdialog.ontimesetlistener () {
@Override
public void Ontimeset (timepicker view, int hourofday, int minute) {
Specifying the start Alarmactivity component
Intent Intent = new Intent (mainactivity.this, Alarmactivity.class);
Create a Pendingintent object
/*
* The difference between pendingintent and intent is that pendingintent deal with what is about to happen.
* For example: in the Notification bar notification jump page, not immediately jump
* Examples of pendingintent are usually obtained through getactivity, Getbroadcast, GetService
*
*/
pendingintent pi = pendingintent.getactivity (mainactivity.this, 0, intent, 0);
Calendar C = calendar.getinstance ();
C.settimeinmillis (System.currenttimemillis ());
C.set (Calendar.hour, hourofday);
C.set (Calendar.minute, MINUTE);
Alarmmanager.set (Alarmmanager.rtc_wakeup, C.gettimeinmillis (), pi);
Toast.maketext (Mainactivity.this, "Set alarm success", Toast.length_short). Show ();
}
}, Currenttime.get (Calendar.hour_of_day), Currenttime.get (Calendar.minute), false). Show ();
}
});
}
}
iOS app Development Simple example