0
我的应用程序basicaly检测到屏幕解锁并弹出一个敬酒。它的做工精细用吐司,但是当我implent的意图,并调用它崩溃的另一项活动..Broadcastreciever不启动活动
package com.androidexample.screenonoff;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.IBinder;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
public class AEScreenOnOffService extends Service {
BroadcastReceiver mReceiver=null;
@Override
public void onCreate() {
super.onCreate();
// Toast.makeText(getBaseContext(), "Service on create", Toast.LENGTH_SHORT).show();
// Register receiver that handles screen on and screen off logic
IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
mReceiver = new AEScreenOnOffReceiver();
registerReceiver(mReceiver, filter);
}
@Override
public void onStart(Intent intent, int startId) {
boolean screenOn = false;
try{
// Get ON/OFF values sent from receiver (AEScreenOnOffReceiver.java)
screenOn = intent.getBooleanExtra("screen_state", false);
}catch(Exception e){}
// Toast.makeText(getBaseContext(), "Service on start :"+screenOn,
//Toast.LENGTH_SHORT).show();
if (!screenOn) {
// your code here
// Some time required to start any service
Toast.makeText(getBaseContext(), "Begin ", Toast.LENGTH_LONG).show();
这里我加入了一个意图开始活动。
Intent intent = new Intent(AEScreenOnOffService.this,postlockscreen.class);
startActivity(intent);
} else {
// your code here
// Some time required to stop any service to save battery consumption
//Toast.makeText(getBaseContext(), "Screen off,", Toast.LENGTH_LONG).show();
}
}
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
}
我已经检查了新的活动类的一切似乎是罚款,但似乎没有任何可以使用的XML ..
你有没有尝试过的意图? – Awadesh
向我们展示此代码发生的错误的logcat –