2017-09-13 4 views
0

こんにちは皆私は開発しているAndroidアプリケーションに問題があります。このアプリは余ったものとして動作し、イベントが発生したときに通知を送信し、通知を送信するタイミングを決定し、アプリケーションがIntentServiceを実装し、IntentServiceがUIスレッドとは異なるスレッドとして動作するため、IntentServiceから通知を送信したいまたは主なスレッドがありますが、インストール後最初にアプリケーションをインストール/実行するとサービスが開始せず、アプリケーションを終了してもう一度実行するとサービスが開始されます。私はなぜこれが起こっているのか知りたがっているのですが、インストール後に誰かがアプリケーションを終了しないと通知が機能しなくなり、「実行後にアプリケーションを終了してください」というユーザには伝えられません。 私は正しい方法でサービスを実装しているかどうかわかりません。手伝っていただけませんか?終了するまでサービスが開始せず、アプリケーションを再実行します - Android

これは私のAndroidのマニフェストです:マニフェストは、デバイスの再起動またはブートとは、通知のためのサービスを呼び出したときに起動することをアプリに許可しますあなたが見ることができるように

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.coninci"> 

<uses-permission android:name="android.permission.INTERNET" /> 
<application 
    android:allowBackup="true" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name" 
    android:roundIcon="@mipmap/ic_launcher" 
    android:supportsRtl="true" 
    android:theme="@style/AppTheme"> 
    <activity android:name=".WelcomeActivity"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
    <activity android:name=".Splashscreen"></activity> 
    <activity android:name=".Registro" /> 
    <activity android:name=".Menuprincipal" /> 
    <activity android:name=".RecyclerViewActivity" /> 
    <activity android:name=".Evento" /> 
    <activity android:name=".Talleres" /> 
    <activity android:name=".Ponencias" /> 
    <activity android:name=".Favoritos" /> 
    <activity android:name=".DetalleEvento" /> 

    <receiver 
     android:name=".NM_RemoteReceiver" 
     android:process=":remote" > 
    </receiver> 

    <service 
     android:name=".NM_RemoteService" 
     android:exported="false" /> 

    <receiver android:enabled="true" 
     android:name=".NM_BootReceiver" 
     android:permission="android.permission.RECEIVE_BOOT_COMPLETED"> 
     <intent-filter> 
      <action android:name="android.intent.action.BOOT_COMPLETED"/> 
      <category android:name="android.intent.category.DEFAULT" /> 
     </intent-filter> 
    </receiver> 

    <service android:name=".NM_BootService"> 
     <intent-filter> 
      <action android:name="ServicioCodigo"></action> 
     </intent-filter> 
    </service> 

</application> 
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> 

。ここで

は私がサービスを実装するクラスです。

このクラスは、マニフェストによって呼び出され、ここから、私は別のIntentServiceクラスに位置しているサービスを呼び出す:

import android.app.Notification; 
import android.app.NotificationManager; 
import android.app.PendingIntent; 
import android.content.BroadcastReceiver; 
import android.content.ContentValues; 
import android.content.Context; 
import android.content.Intent; 
import android.database.Cursor; 
import android.database.sqlite.SQLiteDatabase; 
import android.graphics.BitmapFactory; 
import android.media.RingtoneManager; 
import android.net.Uri; 
import android.support.v4.app.NotificationCompat; 
import android.widget.Toast; 
import java.util.Calendar; 

public class NM_RemoteReceiver extends BroadcastReceiver { 



@Override 
public void onReceive(Context context, Intent intent) { 
    Intent i = new Intent(context, NM_BootService.class); 
    context.startService(i); 

} 
} 

IntentServiceクラス

import android.app.AlarmManager; 
import android.app.IntentService; 
import android.app.NotificationManager; 
import android.app.PendingIntent; 
import android.app.Service; 
import android.content.Context; 
import android.content.Intent; 
import android.os.IBinder; 
import android.support.v4.app.NotificationCompat; 
import android.util.Log; 
import android.widget.Toast; 

public class NM_BootService extends IntentService { 
@Override 
public IBinder onBind(Intent intent) { 
    return null; 
} 

public NM_BootService() { 
    super("NM_RemoteService"); 
} 
@Override 
protected void onHandleIntent(Intent intent) { } 

@Override 
public void onCreate() { 
    super.onCreate(); 
    //I implement notifications here 
} 
@Override 
public void onDestroy() { 
    super.onDestroy(); 
    //Print message when service destroys 
} 
} 

私の英語はあまり良くありません! :) あなたが私を助けることができるなら、私はそれをapreciateします! ありがとうございました!

+0

を増やしてみてください 'アンドロイド:'すべてのサービス内のマニフェストで= "true" を可能にしました。 – Nithin

答えて

1

アラーム(リマインダー)アプリを実装する場合、インテントサービスを呼び出すだけの理由は何ですか?

使用AlarmManager(それはバッテリーを食べるので、賢明にそれを使用する)

https://developer.android.com/training/scheduling/alarms.html