일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
- Mail Server
- mysql
- php 취약점
- 폼메일
- soundpool
- roundcube
- Android
- WebView
- UML
- 안드로이드
- 안드로이드 푸시
- javascript
- dovecot
- C#
- chart.js
- php 시큐어코딩
- PHP
- FCM
- 설치
- C# IO
- not working
- html5
- 안드로이드 gcm
- android 효과음
- 안드로이드 푸쉬
- 자동 생성
- 우분투
- xe
- 자바스크립트
- curl
- Today
- Total
그러냐
안드로이드 service에서 alert dialog 띄우기 본문
출처 : http://stackoverflow.com/questions/21283588/pop-up-alert-dialog-box-from-service-in-android
I'm trying to build activity aware app. I used the activity recognition example from android developers as starting point. In this example the moment the user starts moving notification appears with request to turn on the GPS. I'm trying to replace this notification with an alarm dialog box and some sound. the simple and most common alert box that I found is not working for me since it is imposible to create an allert from service. Thanks to Harsh for giving me an idea of activity. I will post the code the moment it will work. Thank you in advance as promised the working code of an alert box invoked from 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 alert activity .java 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);
// set title
alertDialogBuilder.setTitle("Your Title");
// set dialog message
alertDialogBuilder
.setMessage("Your Message")
.setCancelable(false)
.setNeutralButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// if this button is clicked, just close
// the dialog box and do nothing
stopService(getIntent());
dialog.cancel();
finish();
}
});
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
}
3)alert activity manifest was left empty of code, just a layout 4)the manifest.xml:
<activity
android:name="com.igor.map.MyAlert"
android:theme="@android:style/Theme.Dialog">
</activity>
All works, one thing still has a problem, when i press the Ok button the allert closes but the label of the app stays until I click on screen.
Start an Activity from service, and declare activity as dialog in your manifest. Like this
<activity
android:name="com.example.DialogActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.Dialog
'android' 카테고리의 다른 글
부팅시 서비스(Service) 실행하기 (0) | 2016.01.28 |
---|---|
안드로이드 service에서 포스트로 데이터 주고 받기 httppost 통신 (0) | 2016.01.28 |
안드로이드 블루투스 신호강도 측정하기 (0) | 2016.01.28 |
sendEmptyMessageDelayed 핸들러 재귀호출 (0) | 2016.01.28 |
Handler와 AlarmManager를 통한 Timer 작업 처리 (0) | 2016.01.28 |