从主活动启动服务不起作用(意图服务)



在搜索stackoverflow以查看是否有问题之后,没有一个对此有所帮助。

在我的主要活动中,我有这个:

if (GlobalVars.espera == 0)
{
    GlobalVars.espera = 1;
    try
    {
        bgIntent = new Intent(this, Loadscreen.class);
        startService(bgIntent);
    }
    catch (Exception e)
    {
        GlobalFunctions.toast_message(context, "nao");
    }           
}

当我启动应用程序时,它应该加载打算在后台工作,但事实并非如此。

这是负载屏幕的类:

public class Loadscreen extends IntentService{
MainActivity teste;
private static final String intService = "loadscreen";
public Loadscreen()
{
    super(intService);
    // TODO Auto-generated constructor stub
}
@Override
protected void onHandleIntent(Intent intent)
{
    teste = new MainActivity ();
    try
    {
        teste.inic();
    }
    catch (Exception e)
    {
    }
}   

}

和清单我放了

<service android:name=".Loadscreen"></service>

在它上面,作为应用程序的孩子

即使我有尝试,它也不会进入 catch AKA 错误,但仍然不会进入类加载屏幕。

感谢您的帮助和时间

你有

teste = new MainActivity (); // assuming MainActivity is a Activity class

您正在实例化错误的活动类。

最新更新