i want to play music only one time but the code every minute play it how can i do that ?
public class MainActivity extends AppCompatActivity {
Button BT;
PendingIntent pendingIntent;
public void func()
{
AlarmManager alarmManager=(AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP,System.currentTimeMillis(),1*60*1000,pendingIntent);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent=new Intent(MainActivity.this,sv.class);
pendingIntent=PendingIntent.getBroadcast(MainActivity.this,0,intent,0);
BT=(Button) findViewById(R.id.button);
BT.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
func();
}
});
}
You have the the alarm type 'setInexactRepeating' - which as it suggests ... Repeats. Try using 'set' instead. There is more info here: http://developer.android.com/reference/android/app/AlarmManager.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.