Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 从主活动启动服务不工作(IntentService)_Java_Android - Fatal编程技术网

Java 从主活动启动服务不工作(IntentService)

Java 从主活动启动服务不工作(IntentService),java,android,Java,Android,在搜索stackoverflow查看是否有问题后,没有人在这方面对我有帮助 关于我的主要活动,我有以下几点: if (GlobalVars.espera == 0) { GlobalVars.espera = 1; try { bgIntent = new Intent(this, Loadscreen.class); startService(bgIntent); } catch (Exception e) {

在搜索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");
    }           
}
当我启动应用程序时,它应该加载想要在后台工作的文件,但它不是

以下是loadscreen的类别:

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

您实例化的活动类是错误的。

即使我命令它,它也不会做任何事情,我已经在包含super(intService)的行中添加了一个断点;在调试模式下,它仍然没有进入它的内部,只是从startService(bgIntent);直达终点try@user3310091这是您在实例化活动类时犯的一个错误。您确定这是条件匹配
if(GlobalVars.espera==0)
?是的,它们只传递给1,当它在加载屏幕内的try上执行我想要的操作时,当程序运行时,它从0开始launches@user3310091尝试在if块中记录一些内容,并检查logcat