Android 새로 고침 현재 활동
이 질문에 이미 답변이 있습니다.
- Android 15 답변 에서 활동 새로 고침
ButtonClick에서 현재 활동을 새로 고치도록 Android 앱을 프로그래밍하고 싶습니다. 작업을 수행 할 활동 레이아웃 상단에 하나의 버튼이 있습니다. 버튼을 클릭하면 장치가 다시 시작되는 것처럼 현재 활동이 다시로드됩니다.
감사
public void onClick (View v){
Intent intent = getIntent();
finish();
startActivity(intent);
}
당신은 이것을 시도 할 수 있습니다
finish();
startActivity(getIntent());
이 질문은 이전에 질문되었습니다 . Android 활동을 다시 시작하는 방법
활동에서 활동 recreate()
을 "재 작성"하기 위해 호출 할 수 있습니다 (API 11+).
이것은 새로 고침 버튼 방법이지만 내 응용 프로그램에서 잘 작동합니다. finish ()에서 인스턴스를 종료합니다.
public void refresh(View view){ //refresh is onClick name given to the button
onRestart();
}
@Override
protected void onRestart() {
// TODO Auto-generated method stub
super.onRestart();
Intent i = new Intent(lala.this, lala.class); //your class
startActivity(i);
finish();
}
이것은 여기 에서 본 것처럼 나를 위해 일한 것 입니다.
그것을 사용하거나 정적 클래스 도우미에 추가하고 프로젝트의 어느 곳에서나 호출하십시오.
/**
Current Activity instance will go through its lifecycle to onDestroy() and a new instance then created after it.
*/
@SuppressLint("NewApi")
public static final void recreateActivityCompat(final Activity a) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
a.recreate();
} else {
final Intent intent = a.getIntent();
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
a.finish();
a.overridePendingTransition(0, 0);
a.startActivity(intent);
a.overridePendingTransition(0, 0);
}
}
다시 시작하고 이전 현재 활동의 모든 인스턴스를 삭제해야합니다.
아니, 안돼.
그것은 장소에 데이터를 업데이트해야합니다 (예를 들어, ). 그러면 걱정할 "이전 현재 활동의 인스턴스"가 없습니다.requery()
Cursor
이것을 시도 할 수 있습니다 :
CookieSyncManager.createInstance(this);
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.removeAllCookie();
Intent intent= new Intent(YourCurrent.this, YourCurrent.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
당신이 사용할 수있는:
startActivity(MyClass.this, MyClass.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
가장 쉬운 방법은 전화를 거는 onCreate(null);
것이며 귀하의 활동은 새로운 것과 같습니다.
이를 사용하여 자체 내에서 활동을 새로 고칠 수 있습니다.
finish();
startActivity(getIntent());
대화에서 새로 고칠 활동까지. 첫 활동이 아니라면!
다음과 같이 : mainActivity >> objectActivity >> dialog
대화 클래스에서 :
@Override
public void dismiss() {
super.dismiss();
getActivity().finish();
Intent i = new Intent(getActivity(), objectActivity.class); //your class
startActivity(i);
}
이 시도
간단한 방법
Intent intent=new Intent(Current_Activity.this,Current_Activity.class);
startActivity(intent);
finish();
I think that the best choice for you is using SwipeRefreshLayout View in your layout. Then set RefreshListener like.
mySwipeRefreshLayout.setOnRefreshListener(
new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
Log.i("Fav ", "onRefresh called from SwipeRefreshLayout");
// This method performs the actual data-refresh operation.
// The method calls setRefreshing(false) when it's finished.
request(); // call what you want to update in this method
mySwipeRefreshLayout.setRefreshing(false);
}
}
);
For more details click this link
You can call this method:
recreate();
참고URL : https://stackoverflow.com/questions/6547969/android-refresh-current-activity
'Nice programing' 카테고리의 다른 글
하나의 팝 오버를 표시하고 다른 팝 오버를 숨 깁니다. (0) | 2020.12.09 |
---|---|
스토리 보드를 사용하여 탭 막대 컨트롤러에서 선택한 이미지 설정 (0) | 2020.12.09 |
Swift의 밑줄 버튼 텍스트 (0) | 2020.12.09 |
문자열을 단어 목록으로 변환? (0) | 2020.12.09 |
MySql : 'SUM IF'또는 'COUNT IF'가 가능합니까? (0) | 2020.12.09 |