2013-12-19 20 views
6

にnullを返し、私はそのようなマニフェストでそれを宣言した:getApplicationContextは()私はそれ自身のプロセスでのサービスを持っているサービス

<service 
     android:name="com.discountscatcher.util.PointService" 
     android:configChanges="orientation" 
     android:process=":pointservice" > 
    </service> 

しかしonStartCommand、私はそれが常にApplicationContextを取得しようとしたが、 nullを返します。何が忘れることができますか?

public int onStartCommand(Intent intent, int flags, int startId) { 
    android.os.Debug.waitForDebugger(); 
    Context mContext = getApplicationContext(); 
    return Service.START_STICKY; 
} 

と私はそのようにそれを開始:Myactivity OnCreate

任意のアイデアで

startService(new Intent(getApplicationContext(), PointService.class)); 

+0

をチェックするにはプロセス間通信である http://developer.android.com/guide/components/processes -and-threads.html#IPC –

+2

サービスはコンテキストです。なぜアプリケーションコンテキストが必要ですか? – FunkTheMonk

+0

@FunkTheMonkどのように文字列、drawablesなどのアプリケーションリソースを取得できますか? – whizzzkey

答えて

5

それは、実際のアプリケーション・プロセスとの通信を持っていないので、あなたは

は、アプリケーションがアプリケーション終了後、あなたのサービスから

android:process=":pointservice" 

をこの行を削除するようにしてください...別のプロセスであなたのServiceを実行していますコンテキストはnullになります。ほとんどの場合、別のプロセスでサービスを実行する必要はありません。また、それはお勧めしません。私は何が必要だと思うの詳細については

ここ

  1. Service in another process
  2. service reference Example2
+0

別のプロセスでサービスを開始する理由を教えてください。 – whizzzkey

+0

2つの例が明確に説明されています。 –

関連する問題