1

サービスを使用してタイマーを実行しています。ロック画面のコードを保持するサービスから新しいアクティビティを呼び出す必要があります。サービスからそのアクティビティを開始する意図を使用しています。その後、エラーが発生します

   java.lang.RuntimeException: Unable to instantiate activity ComponentInfo

マニフェスト ファイルにスクリーンロック アクティビティを登録済みです。

My Service .java

 public class BgTimerService extends Service
 {

  static long second;
  static long min;
  Intent I;
  Bundle b; 
  @Override
  public void onCreate()
  {
    super.onCreate();
    showTime();     
  }
  public void showTime()
  {
    CountDownTimer countdowntimer;
    long time;

    time = (1 * 10 * 1000);
    countdowntimer = new CountDownTimer(time, 1000)
    {

        @Override
        public void onTick(long millisUntilFinished)
        {
            // TODO Auto-generated method stub

            BgTimerService.second = millisUntilFinished / 1000;
            BgTimerService.min = 0;
            while (BgTimerService.second >60)
            {
                if (BgTimerService.second > 60)
                {
                    BgTimerService.second = BgTimerService.second - 60;
                    BgTimerService.min++;

                }
            }
        }

        @Override
        public void onFinish()
        {
            // TODO Auto-generated method stub
            Toast.makeText(getApplicationContext(), "Hello World",
                    Toast.LENGTH_SHORT).show();
            stopSelf();
            Intent in=new Intent(BgTimerService.this,LockScreenActivity.class);
            in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(in);
        }
    }.start();
}

@Override
public IBinder onBind(Intent arg0)
{
    // TODO Auto-generated method stub
    return null;
}

LockscreenActivity.java

 public class LockScreenActivity extends DeviceAdminReceiver
 {

  public void onEnabled(Context context, Intent intent)
  {
    showToast(context, "Sample Device Admin: enabled");
  }

@Override
 public CharSequence onDisableRequested(Context context, Intent intent)
 {
    return "This is an optional message to warn the user about disabling.";
     }

@Override
public void onDisabled(Context context, Intent intent)
{
    showToast(context, "Sample Device Admin: disabled");
}

void showToast(Context context, CharSequence msg)
{
    Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();

}

public static class Myclass extends Activity
{

    protected PowerManager.WakeLock mWakeLock;
    DevicePolicyManager mDPM;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        // setContentView(R.layout.main);

        mDPM = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
        // mDPM.lockNow();

        ComponentName mAdminName = new ComponentName(Myclass.this,
                LockScreenActivity.class);


        if (!mDPM.isAdminActive(mAdminName))
        {
            Intent intent = new Intent(
                    DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
            intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN,
                    mAdminName);
            intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
                    "is locked");
            intent.putExtra("force-locked",
                    DeviceAdminInfo.USES_POLICY_FORCE_LOCK);

            startActivityForResult(intent, 1);
            System.out
                    .println("The Device Could not lock because device admin not enabled");
            // mDPM.lockNow();
        } else
        {
            System.out.println("The Device  device admin enabled");
            Intent intent = new Intent(
                    DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
            intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN,
                    mAdminName);
            intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
                    "onEnabled");
            mDPM.lockNow();
            mDPM.setMaximumTimeToLock(mAdminName, 0);
            intent.putExtra("force-locked",
                    DeviceAdminInfo.USES_POLICY_FORCE_LOCK);

            startActivityForResult(intent, 1);

        }

    }
}

}

私のmanifest.xmlは

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myapp.screenlock"
android:versionCode="1"
android:versionName="1.0" >
 <uses-sdk
    android:minSdkVersion="8" />
<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:name=".BgTimerActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <service android:name=".BgTimerService" />

    <activity android:name=".LockScreenActivity" >
    </activity>
    <activity
        android:name=".LockScreenActivity$Myclass"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
        </intent-filter>
    </activity>
    <receiver
        android:name=".LockScreenActivity"
        android:label="device_admin"
        android:permission="android.permission.BIND_DEVICE_ADMIN" >
        <meta-data
            android:name="android.app.device_admin"
            android:resource="@xml/my_admin" />
        <intent-filter>
            <action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
        </intent-filter>
    </receiver>
</application>
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />

誰かが私がどこで間違ったのか理解できますか?

4

0 に答える 0