【发布时间】:2014-12-18 21:36:03
【问题描述】:
我遇到了这个问题,无法让它工作。这是空的主类别启动器活动的代码,如果服务未运行或用户未通过身份验证,则必须显示启动屏幕,否则启动对话活动。
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
public class EntryPoint extends Activity {
private IAppManager imService;
private ServiceConnection mConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName className, IBinder service) {
imService = ((IMService.IMBinder) service).getService();
// this is not starting activity :(
// Start converstion activity if service running and user ok
if (imService.isUserAuthenticated() == true) {
try {
Intent i = new Intent(EntryPoint.this, Conversations.class);
startActivity(i);
finish();
} catch (Exception e) {
e.printStackTrace();
}
}
}
// this is not working
// start login activity if service disconnected
public void onServiceDisconnected(ComponentName className) {
imService = null;
try {
Intent intent = new Intent(getBaseContext(), Splash.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intent);
finish();
} catch (Exception e) {
e.printStackTrace();
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Start and bind the imService
startService(new Intent(EntryPoint.this, IMService.class));
}
@Override
protected void onPause() {
super.onPause();
try {
unbindService(mConnection);
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
protected void onResume() {
super.onResume();
try {
bindService(new Intent(EntryPoint.this, IMService.class),
mConnection, Context.BIND_AUTO_CREATE);
} catch (Exception e) {
e.printStackTrace();
}
}
}
当我运行应用程序时,Conversations 和Splash 活动都没有运行,而是我看到空活动:( 也没有错误,只是运行空的EntryPoint 活动,实际上应该启动其他活动之一活动。
有谁知道我在这里做错了什么?
【问题讨论】: