无法在Android中启动意图? [英] unable to start intent in android?

查看:80
本文介绍了无法在Android中启动意图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在启动我使用过的新服务时

startService(new Intent(this,ser.class);

n m在日志猫中出现错误,无法在android中启动意图.


demoseractivity.java

while starting a new service i have used

startService(new Intent(this, ser.class);

n m getting error in log cat unable to start intent in android.


demoseractivity.java

package com;

import com.demoser.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class demoserActivity extends Activity implements OnClickListener {
	private static final String TAG = "ServicesDemo";
	  Button buttonStart, buttonStop;

	  @Override
	  public void onCreate(Bundle savedInstanceState) {
		  super.onCreate(savedInstanceState);
	    setContentView(R.layout.main);

	    buttonStart = (Button) findViewById(R.id.buttonStart);
	    buttonStop = (Button) findViewById(R.id.buttonStop);

	    buttonStart.setOnClickListener(this);
	    buttonStop.setOnClickListener(this);
	  }

	  public void onClick(View src) {
	    switch (src.getId()) {
	    case R.id.buttonStart:
	      Log.d(TAG, "onClick: starting srvice");
	      startService(new Intent(this, ser.class));
	      break;
	    case R.id.buttonStop:
	      Log.d(TAG, "onClick: stopping srvice");
	      stopService(new Intent(this, ser.class));
	      break;
	    }
	  }
	}



ser.java



ser.java

package com;

import com.demoser.R;

import android.app.Service;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;
import android.R.layout.*;
import android.app.Activity;
import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TextView;

public class ser extends Service

{
	private static final String TAG = "MyService";
MediaPlayer player;
@Override
public IBinder onBind(Intent intent) {
return null;
}

public void onCreate(Bundle savedInstanceState) {
    super.onCreate();
  //  setWallpaper(R.drawable.ic_launcher);
	Toast.makeText(this, "My Service Created", Toast.LENGTH_LONG).show();
	Log.d(TAG, "onCreate");
	player = MediaPlayer.create(this, R.raw.demo);
	player.setLooping(false); // Set looping
}

	
@Override
public void onDestroy() {
	Toast.makeText(this, "My Service Stopped", Toast.LENGTH_LONG).show();
	Log.d(TAG, "onDestroy");
	player.stop();
}

public void onStartCommand(Intent intent, int startid) {
	Toast.makeText(this, "My Service Started", Toast.LENGTH_LONG).show();
	Log.d(TAG, "onStart");
	player.start();
}
}


main.xml只有两个按钮

并且清单具有

服务已启用="true" android:name =.ser"

内部应用程序标记


main.xml just has two buttons

and manifest has

service enabled="true" android:name=".ser"

inside application tag

推荐答案

需要描述有关您的错误的更多信息.这可能是您的ser.class的问题.但是,请从此处了解如何使用意图. .
http://www.vogella.com/articles/AndroidIntent/article.html [ ^ ]
Need to describe more about your error.It may be a problem of your ser.class.However,see from here how to use an intent..
http://www.vogella.com/articles/AndroidIntent/article.html[^]


这篇关于无法在Android中启动意图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆