2011-10-28 16 views
0

AlarmManagerを使用して間隔ごとにアクティビティを呼び出しましたが、間隔を変更する必要があります。このアクティビティは、私がpendingIntentに変更した別の関数です。 呼び出し元のクラスを以下に示します。これもメインクラスです。呼び出されたクラスは、呼び出し元のクラスの後に表示されます。最後に、マニフェストファイルがあります。マニフェストファイルには、エラーの原因が含まれている可能性があります。サービスのインテントを開始できません:見つからない

Timer_test: 

    package com.timer_test; 

    import android.app.Activity; 
    import android.app.AlarmManager; 
    import android.app.PendingIntent; 
    import android.content.Intent; 
    import android.os.Bundle; 
    import android.os.SystemClock; 
    import android.view.View; 
    import android.view.View.OnClickListener; 
    import android.widget.Button; 

public class Timer_testActivity extends Activity { 
    /** Called when the activity is first created. */ 

    private PendingIntent mAlarmSender; 
    int update_freq = 1; 
    Intent toast_make; 
    int interval; 

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

    Button button1 = (Button)findViewById(R.id.button1); 
    Button button3 = (Button)findViewById(R.id.button3); 
    Button button5 = (Button)findViewById(R.id.button5); 
    Button button10 = (Button)findViewById(R.id.button10); 

    toast_make = new Intent("com.timer_test.toast_testClass"); 
    mAlarmSender = PendingIntent.getService(Timer_testActivity.this, 0, toast_make   ,0); 

    button1.setOnClickListener(new OnClickListener(){ 
     public void onClick(View arg0){ 
      update_freq = 1; 
      timer_schedule(); 
    } 
    }); 

    button3.setOnClickListener(new OnClickListener(){ 
     public void onClick(View arg0){ 
      update_freq = 3; 
      timer_schedule(); 
    } 
    }); 

    button5.setOnClickListener(new OnClickListener(){ 
     public void onClick(View arg0){ 
      update_freq = 5; 
      timer_schedule(); 
    } 
    }); 

    button10.setOnClickListener(new OnClickListener(){ 
     public void onClick(View arg0){ 
      update_freq = 10; 
      timer_schedule(); 
    } 
    }); 
} 

    public void timer_schedule(){ 

    long firstTime = SystemClock.elapsedRealtime(); 

    interval = update_freq*1000; 
    AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE); 
    am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, interval, mAlarmSender); 

} 

package com.timer_test; 

import android.app.Activity; 
import android.os.Bundle; 
import android.widget.Toast; 

public class toast_test extends Activity{ 

public void onCreate(Bundle icicle){ 
    super.onCreate(icicle); 
    setContentView(R.layout.main); 

    onClick("yes"); 
} 

public void onClick(String n) { 
    Toast.makeText(toast_test.this,n, 
     Toast.LENGTH_SHORT).show(); 
    } 

    } 


    <?xml version="1.0" encoding="utf-8"?> 
    <manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.timer_test" 
    android:versionCode="1" 
    android:versionName="1.0"> 
    <uses-sdk android:minSdkVersion="8" /> 

<application android:icon="@drawable/icon" android:label="@string/app_name"> 
    <activity android:name=".Timer_testActivity" 
       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="com.timer_test.toast_test"/> 

    </application> 
</manifest> 

答えて

1

toast_test活動で、マニフェストにあなたがサービス

+0

true..Howeverとして、それを宣言し、私はpendingIntentとしてtoast_testを使用する例を踏襲し、AlarmManagerのgetSystemServiceでそれを開始..私は開始することができます任意のアクティビティを意図として使用し、AlarmManagerを使用しますか? – user301

+0

私はあなたが何を求めているのかはっきりしていませんが、インテントはアクティビティ間でメッセージが渡されるようなものです。インテントを送信することでアクティビティを開始できます。あなたはあなたのマニフェストファイルの中にインテントフィルタをあなたのアクティビティに合わせて書くだけでよいのです。 – Vivek

関連する問題