簡體   English   中英

Android從后台服務開始活動

[英]Android starting an activity from background service

public void onCreate()
{ 
    super.onCreate();
    Thread tt = new Thread(){
        public void run()
        {
           Intent dialogIntent = new Intent(getBaseContext(), ActivityClass.class);
           dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
           getApplication().startActivity(dialogIntent);
        }
    };
    tt.start();
}

通過這種方式,我嘗試從服務中調用我的活動,但是我的應用程序崩潰了,請幫幫我

參考以下鏈接:

http://developer.android.com/guide/components/services.html

startService(i1); //啟動服務。

使用startActivityForResult()而不是startActivity()因為在服務中我們使用startActivityResult()方法,因為廣播接收器將給出onresultActivity ..的響應,因此您可以使用此行

使用startActivityForResult(intent,requestcode )代替startActivity()

謝謝..

做就是了,

   public void onCreate() {
    super.onStart(intent, startId);
    Intent in=new Intent().setClass(yourserviceclass.this,ActivityClass.class);
     in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(in);
}

暫無
暫無

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

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