私は新しいprogrammer.i iは次のようにConnectionConfigurationオブジェクトを使用して接続を作成しているserver.In XMPPを使ってチャットを取得するために、この実装をサンプルアプリケーションを実装したいと思います午前:私はXMPPConnectionにconnConfigオブジェクトを渡していますあるアクティビティから別のアクティビティへ同じxmpp接続を取得する方法は?
ConnectionConfiguration connConfig =new ConnectionConfiguration(host, Integer.parseInt(sport), service);
を接続メソッドを呼び出すことによってクラス私は接続を取得していると私はボタンを使用してログインするpassword.toログインするユーザー名パンドパスワードで渡すログインメソッドを呼び出すことによって私はボタンをクリックしたとき私はインテントを変更するために使用しているactivity.One私は別のアクティビティで同じ接続を取得したいと思うアクティビティを変更しています。
次のように私はLoginActivity用のコードを書かれている:
public class ChatPage extends Activity {
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.chatpage);
//How to get the same XMPPConnection from LoginActivity here
}
}
をChatPageActivityへLoginActivityから同じ接続を取得する方法:
public class LoginActivity extends Activity
{
ConnectionConfiguration connConfig ;
XMPPConnection connection;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.setting);
((Button)findViewById(R.id.login)).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0)
{
connConfig =new ConnectionConfiguration(host, Integer.parseInt(sport), service);
connection = new XMPPConnection(connConfig);
connection.connect();
connection.login(uname, password);
}
});
}
}
を次のように私はChatPageActivityを書かれていますか?
すべてのボディは
次に、あなたのLoginActivityには、接続を設定します同じアプリケーションのXMPPConnections、アプリケーションを介して私は特定の接続を取得したい。どのように私はこのように維持することができます.. –
その特定のコレクションはどのように識別されますか?文字列で?私はちょうどそう仮定する。これを行うには、この "private XMPPConnection connection = null;"を変更します。この "プライベートマップ接続=新しいHashMap ();" getterとsetterを接続名(文字列)を取得するように変更すると、接続をストアに保存するだけです。 –
私はインデックス付きのArrayListを使ってみましたが運がありません。インデックスアウトオフサイズの例外を与える、私はこのようにしようとします.. –