0

I tried to implement a share button in my Android project as seen on this video.

<Button
    android:id="@+id/shareButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:onClick="btnClicked"
    android:text="@string/share" />

public void btnClicked(View v){
    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.setType("text/plain");
    String shareBody = "Length: " + jump.length + "Time: " + jump.getTime();
    String shareSub = "I just jumped with my " + jump.Sport.toString();
    shareIntent.putExtra(Intent.EXTRA_SUBJECT,shareSub);
    shareIntent.putExtra(Intent.EXTRA_TEXT,shareBody);
    startActivity(Intent.createChooser(shareIntent,"Share Jump"));
}

However, I get this error message when pressing my button.

2019-03-04 19:23:41.130 7911-7911/com.google.android.apps.messaging E/FirebaseInstanceId: Failed to start service while in background: java.lang.IllegalStateException: Not allowed to start service Intent { act=com.google.firebase.INSTANCE_ID_EVENT pkg=com.google.android.apps.messaging cmp=com.google.android.apps.messaging/com.google.firebase.iid.FirebaseInstanceIdService (has extras) }: app is in background uid UidRecord{8e293ee u0a55 RCVR idle change:idle|uncached procs:1 seq(0,0,0)}

I wanted to know how I can fix the problem.

Thanks in advance!

Bryan
  • 14,756
  • 10
  • 70
  • 125
Florian Jäger
  • 157
  • 1
  • 14
  • Possible duplicate of [Android 8.0: java.lang.IllegalStateException: Not allowed to start service Intent](https://stackoverflow.com/questions/46445265/android-8-0-java-lang-illegalstateexception-not-allowed-to-start-service-inten) – Теодор Митев Mar 04 '19 at 18:59
  • It looks like the error message is coming from the Messages app. Does the chooser actually show up? Or does the error occur before the chooser is visible? – Bryan Mar 04 '19 at 19:13
  • The chooser doesn't show and it closes the activity. (The one where the shareButton is in) – Florian Jäger Mar 04 '19 at 19:34

0 Answers0