- 전체
- android studio
- Android SDK
- Android NDK
- Android ADK
- Android Etc. Lib.
- Android dalvik VM
- Android 보안
- PhoneGap
- AOSP 개발
- MIT App Inventor 2
- kivy (python)
- ionic framework
- Kotlin (코틀린)
- React Native
Android SDK [Android SDK] Making Android WebView autorefresh periodically
2024.05.01 17:02
[Android SDK] Making Android WebView autorefresh periodically
I'm trying to create a hybrid application in Android that has a web view that's supposed to refresh every five minutes or so, or a few seconds after the user has done a change in the service. Most solutions that I've tried can be summarized into this SO question's answer. The problem is that everytime the application tries to refresh the web view through that, the software crashes because "an UI element has been called from non-UI thread".
Is there another alternative? I think I can do a periodical refresh through Javascript in the web page itself, but considering that our application has been designed to run even if there's no network and we can't then refresh it when user changes the status of the native side, it's not optimal. Does anyone have any suggestions?
Thanks in advance
---- Answer ----
Using a Toast as an example as how you can keep calling it. You can call the reload(); after a user changes information rather than the onCreate.
Load in the oncreate
Toast.makeText(LogThirdPager.this, "Hello", Toast.LENGTH_SHORT).show();
// mWebview.loadUrl("http://www.google.com");
reload();
Then call this after it. It will continue to reload the page every 5 seconds for example.
public void reload() {
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
// Do something after 5s = 5000ms
Toast.makeText(LogThirdPager.this, "Hello", Toast.LENGTH_SHORT).show();
reload();
// mWebview.loadUrl("http://www.google.com");
}
}, 5000);
}
[출처] https://stackoverflow.com/questions/28255214/making-android-webview-autorefresh-periodically
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
댓글 0
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
|---|---|---|---|---|
| 9 |
android webview로 javascript 호출 및 이벤트 받기(연동하기)
| 졸리운_곰 | 2018.03.19 | 1405 |
| 8 |
지니모션 설치 방법 총정리 (한글키보드 + 구글플레이 설치)
| 졸리운_곰 | 2016.04.23 | 1065 |
| 7 |
Flurry를 사용해보자, Flurry란 무엇인가? Flurry를 이용한 어플 사용자 통계분석하기
| 졸리운_곰 | 2014.12.01 | 505 |
| 6 |
Howto Build Android KitKat (4.4) for the Google Nexus 5December 1, 2013
| 졸리운_곰 | 2014.01.23 | 6576 |
| 5 |
넥서스5 소스 빌드 : Nexus5 Source build
| 가을의 곰을... | 2013.12.20 | 10608 |
| 4 | Samsung Galaxy 안드로이드 커널 빌드 | 가을의 곰을... | 2013.12.12 | 12419 |
| 3 |
넥서스7 소스 빌드 방법
| 가을의 곰을... | 2013.12.12 | 9886 |
| 2 |
안드로이드 플랫폼 개발 (한글)
| 가을의 곰을... | 2013.12.07 | 10780 |
| 1 | 안드로이드 플랫폼 개발 | 가을의 곰을... | 2013.11.17 | 10563 |

