I am trying to create an activity study application. As a starting point, I used an example of activity recognition from Android developers. In this example, when the user starts moving, a notification appears asking you to turn on the GPS. I am trying to replace this notification with an alarm dialog and some sound. The simple and most common alert window that I found does not work for me, since it is impossible to create an alert from a service. Thanks to Harsch for giving me an idea of the activities. I will send the code at the moment when it will work. Thanks in advance, as promised, the working code of the warning window called from the service: 1) the code in the service file:
Intent intent;
intent = new Intent(this, MyAlert.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
2) the code in the .java activity file:
public class MyAlert extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_alert);
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
alertDialogBuilder.setTitle("Your Title");
alertDialogBuilder
.setMessage("Your Message")
.setCancelable(false)
.setNeutralButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
stopService(getIntent());
dialog.cancel();
finish();
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
3) ,
4) manifest.xml:
<activity
android:name="com.igor.map.MyAlert"
android:theme="@android:style/Theme.Dialog">
</activity>
, , Ok, , , .