2

私の getIntent() メソッドが Android サービスと onStartCommand() メソッド内で定義されていない理由を知っている人はいますか?

   @Override
public int onStartCommand(Intent intent, int flags, int startId){
super.onStartCommand(intent, startId, startId);

Intent i = getIntent();
Bundle extras = i.getExtras();
filename = extras.getString("filename");


 return START_STICKY;
}
4

3 に答える 3

4

インテントは関数のパラメータとして渡されるため...

onStartCommand(Intent intent, ...
    Bundle extras = intent.getExtras();
于 2012-10-16T08:18:49.080 に答える
2

getIntent()メソッドはサービスではなくアクティビティです。アクティビティで現在のインテントを取得したい場合は、getIntent()メソッドを呼び出してインテントを取得できます。サービスでは、onStartCommand()メソッドにはすでにパラメータ インテントがあるため、インテントで渡された追加データを取得できます。

メソッドからすでにintentオブジェクトを取得していますonStartCommand()。確認してください。

于 2012-10-16T08:19:16.420 に答える
2

クラスgetIntentに () メソッドはありません。Service渡されたインテント引数を使用できますonStartCommand

于 2012-10-16T08:19:37.733 に答える