0
我製作了鬧鐘,一切正常。在onReceive調用課堂活動以在後臺運行
內部公共類AlarmReceiver擴展BroadcastReceiver我有以下的工作代碼下面。我的問題是如何調用一個活動類與鈴聲運行平行(背景)?
另外我嘗試了下面的代碼,但它將我重定向到reffered類,如何避免它並調用並運行此類活動但不更改用戶界面?
public class AlarmReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
Toast.makeText(context, "Alarm! Wake up! Wake up!", Toast.LENGTH_LONG).show();
Uri alarmUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
if (alarmUri == null)
{
alarmUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
}
Ringtone ringtone = RingtoneManager.getRingtone(context, alarmUri);
ringtone.play();
Intent i = new Intent(context, testactivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
我也與波紋管代碼創建測試活動的java類:
public class testactivity extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.testactivity);
Toast.makeText(this, "this is my Toast message!", Toast.LENGTH_LONG).show();
}
}
任何建議嗎?
你在這裏面臨什麼問題?說明? –