簡體   English   中英

來自主要活動的startService不起作用(IntentService)

[英]startService from main activity not working (IntentService)

在搜索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錯誤,但是仍然不會進入Loadscreen類。

感謝您的幫助和時間

你有

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

您正在實例化Activity類,這是錯誤的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM