2012-05-11 5 views
5

Googleマップアプリケーションの作成中にAndroidに質問があります。別のクラスからのアクティビティのクローズ

私は

public class MapCallActivity extends MapActivity { 
    classA class = new classA(this); 
    classA.callMethod(); 
} 

以下のように一つの活性がclassAは、以下のように定義されました:

public class classA{ 
    public classA(Context context){ 
    this.myContext = context; 
} 

    void callMethod(){ 
     if (isFileValid) { 
     <do_something...>; 
     } else { 
     <call_the_activity's finish() method>; 
     } 
    } 
} 

MapCallActivityが閉じるように、私は<call_the_activity's finish() method>を行うことができます方法はありますか?

ご協力いただきましてありがとうございます。

答えて

27
public class classA{ 
    public classA(Context context){ 
     this.myContext = context; 
    } 

    void callMethod(){ 
     if(isFileValid){ 

     }else{ 
      ((Activity)myContext).finish(); 
     } 
    } 
} 
+0

オブジェクトを直接閉じるためにキャストする方法はありませんか? – curlyreggie

+0

他のクラスにこのアクティビティの参照がある場合。できる。しかし、他の活動やサービスはできません。 –

+0

その助けをありがとう。私は今質問がより明確になるように質問を再構成しました。あなたのコードはそれでも使えますか? – curlyreggie

関連する問題