realm results empty after clearing app from multitask using a service
<p>i have a service that downloading some files using <code>ion</code> library and when the download finished i want to save the downloaded files to a database <code>realm database</code>
the problem is when the user clearing the app from multitask the app crashes and shows <code>ArrayIndexOutOfBoundsException</code> in logcat
i think the problem is that the model class getting destroyed when app is cleared</p>

<p>here is the code</p>

<p>//Service Code</p>

<pre><code>List&lt;Surah&gt; surahList;

 @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        if (intent != null)
            reciterName = intent.getStringExtra("reciterName");

        surahList = realm.where(Surah.class).equalTo("reciterName", reciterName).findAll();
        Surah surah = surahList.get(10);
        String folderName = surah.getReciterName() + " " + surah.getRewaya();
        File path = new File(Environment.getExternalStorageDirectory() + "/Quran Sound/" + folderName + "/" + surah.getSurahNumberMp3());


        NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
        builder
                .setSmallIcon(R.drawable.ic_stat_noti);
         final NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        notificationManager.notify(2, builder.build());
        Ion.with(this)
                .load(surah.getSurahLink())
                .write(path)
                .setCallback(new FutureCallback&lt;File&gt;() {
                    @Override
                    public void onCompleted(Exception e, File result) {
                        Toast.makeText(DownloadService.this, result + "", Toast.LENGTH_SHORT).show();
                        Log.d("3llomi", "ion Download Finished!");
                        notificationManager.cancel(2);
                        stopSelf();
                    }
                });

        return START_STICKY;
    }
</code></pre>

<p>//Logcat </p>

<pre><code>FATAL EXCEPTION: main
Process: com.devlomi.quransound, PID: 4424
java.lang.RuntimeException: Unable to start service com.devlomi.quransound.DownloadService@8f466f2 with null: java.lang.ArrayIndexOutOfBoundsException: rowIndex &gt; available rows: 10 &gt; 0
    at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3027)
    at android.app.ActivityThread.-wrap17(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1442)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5417)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
 Caused by: java.lang.ArrayIndexOutOfBoundsException: rowIndex &gt; available rows: 10 &gt; 0
    at io.realm.internal.TableView.nativeGetSourceRowIndex(Native Method)
    at io.realm.internal.TableView.getSourceRowIndex(TableView.java:128)
    at io.realm.RealmResults.get(RealmResults.java:205)
    at io.realm.RealmResults.get(RealmResults.java:70)
    at com.devlomi.quransound.DownloadService.onStartCommand(DownloadService.java:104)
    at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3010)
    at android.app.ActivityThread.-wrap17(ActivityThread.java) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1442) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:148) 
    at android.app.ActivityThread.main(ActivityThread.java:5417) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
</code></pre>