2013-06-14 3 views
0

특정 프로세스의 대기 표시 줄을 표시해야 할 때 호출하는 사용자 정의 대화 상자 활동 클래스가 있습니다. 그 활동을 끝내지 못했습니다. 또는 그 마무리 방법을 호출하는 법을 모르겠지만, 클래스의 객체를 통해 호출하고 있습니다. WaitDialogManager 클래스의 코드는 아래에 있습니다. 그리고 나는 그것을 위해 방송 수신기를 사용하지 않으려는 ...활동이 시작되지 않은 클래스에서 활동을 완료하는 방법

WaitDialogManager

패키지 com.android.remotewipedata;

import android.app.Activity; import android.os.Bundle; import android.view.Window; 가져 오기 android.widget.TextView;

공용 클래스 WaitDialogManager이 활동 {

TextView waitTitle, waitMessage; 

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    requestWindowFeature(Window.FEATURE_NO_TITLE); 
    setContentView(R.layout.wait_dialog); 

    String title = getIntent().getStringExtra("waitDialogTitle"); 
    String message = getIntent().getStringExtra("waitDialogMessage"); 

    waitTitle = (TextView) findViewById(R.id.wait_dialog_title); 
    waitMessage = (TextView) findViewById(R.id.wait_dialog_message); 
    waitTitle.setText(title); 
    waitMessage.setText(message); 
} 

public void dismissWaitDialog(){ 
    this.finish(); 
    System.out.println("Finish Called"); 
} 
} 

를 확장하고 이것이 내가이 활동을 호출하고 메소드의 완료 후 완료하려고 곳이다, 그 이외의 활동 클래스에 대한 코드는

이하 이 대화 상자에 대한 ServerUtilities

public final class ServerUtilities { 
    //Other code 
public static WaitDialogManager wdManager = new WaitDialogManager(); 

static boolean register(final Context context, String name, String email, 
     final String regId) { 

      // Starting WaitDialogManager activity here 
    context.startActivity(new Intent(context, WaitDialogManager.class) 
      .putExtra("waitDialogTitle", "Please wait...") 
      .putExtra("waitDialogMessage", 
        "Registering device on Server...") 
      .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); 

    String serverUrl = SERVER_URL + "/register.php"; 
    Map<String, String> params = new HashMap<String, String>(); 
    params.put("regId", regId); 
    params.put("name", name); 
    params.put("email", email); 

    // Try to register on server for a number of times 
    long backoff = BACKOFF_MILLI_SECONDS + random.nextInt(1000); 
    for (int i = 1; i <= MAX_ATTEMPTS; i++) { 
     try { 
      post(serverUrl, params); 
      System.out.println("Parameters: " + params); 
      GCMRegistrar.setRegisteredOnServer(context, true); 
      return true; 
     } catch (IOException e) { 
      if (i == MAX_ATTEMPTS) { 
       break; 
      } 
      try { 
       Thread.sleep(backoff); 
      } catch (InterruptedException e1) { 
       Thread.currentThread().interrupt(); 
       return false; 
      } 
      backoff *= 2; 
     } 
    } 
    wdManager.dismissWaitDialog(); 
    return false; 
} 

은 카릭 내가 수동으로이 사라집니다 다시 버튼이 사라 지도록 register() 방법이 끝나면 사라지거나 사라지 길 원합니다. 감사합니다

+1

public class WaitDialogManager extends Activity { public static Activity context = null; // Current Activity public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.wait_dialog); .... } } 

그리고 타격과 같은 ServerUtilities에 전화를 정적 Activity 참조를 선언 한 후) (context.finish를 호출; – Raghunandan

+0

어떻게 그 문맥을 얻을 수 있습니까? 해당 클래스의 Context를 반환하는 메서드를 호출하려고했지만 동일한 결과가 반환됩니다. – Saqib

+0

당신은 컨텍스트를 얻을 수 없습니다, 그것은 parcelable 아니에요. 가능하다하더라도, finish()가 실제로 실행되지 않을 것이라고 생각합니다. 활동이 실행 상태로 돌아 왔을 것입니다. 즉, 내 대답에서 추천 한 것을 수행하고'startActivityForResult'를 사용할 수 있다는 것을 의미합니다. – Ali

답변

0

현재 활동의 정적 참조를 아래와 같이 WaitDialogManager 클래스에서 취해서 해결했습니다. WaitDialogManager 클래스에서, 당신은 활동 클래스의 컨텍스트가 필요합니다

public final class ServerUtilities { 
//Other code 

static boolean register(final Context context, String name, String email, 
    final String regId) { 

     // Starting WaitDialogManager activity here 
     context.startActivity(new Intent(context, WaitDialogManager.class) 
     .putExtra("waitDialogTitle", "Please wait...") 
     .putExtra("waitDialogMessage", 
       "Registering device on Server...") 
     .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); 

String serverUrl = SERVER_URL + "/register.php"; 
Map<String, String> params = new HashMap<String, String>(); 
params.put("regId", regId); 
params.put("name", name); 
params.put("email", email); 

// Try to register on server for a number of times 
long backoff = BACKOFF_MILLI_SECONDS + random.nextInt(1000); 
for (int i = 1; i <= MAX_ATTEMPTS; i++) { 
    try { 
     post(serverUrl, params); 
     System.out.println("Parameters: " + params); 
     GCMRegistrar.setRegisteredOnServer(context, true); 
     WaitDialogManager.context.finish(); // And this is how it works 
     return true; 
    } catch (IOException e) { 
     // Exception handled 
    } 
} 
return false; 
} 
0

제 경험상 기술적으로 이것을 할 수 없습니다. 그래도 할 수있는 일은 startActivityForResult으로 두 번째 활동을 시작한 다음 두 번째 활동이 끝나면 호출 활동이 종료되어야 함을 나타내는 플래그를 다시 전달할 수 있습니다. 이 프로세스는 매우 빠르므로 사용자는 호출 활동이 아직 열려 있음을 알 수 없습니다. 첫 번째/부르는 활동이 항상 종료 되어야만하는 경우 매니페스트에서 활동에 대해 android:noHistory="true"을 설정할 수 있습니다.

관련 문제