【发布时间】:2011-11-25 18:56:32
【问题描述】:
我是新程序员。我想使用 xmpp 服务器实现用于聊天的示例应用程序。在此实现中,我使用 ConnectionConfiguration 对象创建了连接,如下所示:
ConnectionConfiguration connConfig =new ConnectionConfiguration(host, Integer.parseInt(sport), service);
我通过调用连接方法将 connConfig 对象传递给 XMPPConnection 类,我正在获取连接,并通过调用登录方法传递用户名和密码,然后我登录到密码。登录我使用的是按钮。当我点击按钮时我正在使用 Intent 更改活动。我正在更改活动,我想在另一个活动中获得相同的连接。
我为 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如下:
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
}
}
如何获得从 LoginActivity 到 ChatPageActivity 的相同连接?
请任何人帮助我
【问题讨论】: