2013-07-31 54 views
0

的活動,我運行一個服務,並且我需要這個活動讓長按click監聽器獲取其他活動或主屏幕中的座標,然後啓動一個活動來顯示座標。我該怎麼辦?我現在需要啓動一個服務

回答

0

使用意向開始新的活動,通過在束座標的值或意向額外

0
Intent dialogIntent = new Intent(getBaseContext(), myActivity.class); 
dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
getApplication().startActivity(dialogIntent); 

或者 從溶液中發佈由MarcinGil

android.app.Service是後裔的android.app.Context,所以你可以直接使用startActivity。但是,由於您在任何活動之外開始此任務,因此您需要在意圖上設置FLAG_ACTIVITY_NEW_TASK標誌。

例如:

Intent i = new Intent(); 
i.setClass(this, MyActivity.class); 
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
startActivity(i);  
where this is your service. 
0

只是把追蹤您的OnCreate()的代碼在你的服務

Intent intent = new Intent(Your_Context, Your_Class); 
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
startActivity(intent); 
相關問題