Challenge :: Announcing Events

Hi @cstewart. I added the following method to my app’s class. I found a bug and I’m not sure how to fix it and would appreciate your help.

Repro Steps:

  1. Turn on Talkback
  2. Run the app
  3. Double tap the + button to create a new crime
  4. Double tap the photo button to go to the camera app
  5. Double tap the back button to return to the CriminalIntent app

Observed Result:

  • User hears the announcement “Crime Scene Photo set”

Expected Result:

  • User doesn’t hear the announcement “Crime Scene Photo set”


Snippet from
public void onResume() {
    if (mPhotoView.getDrawable() != null) {
        mPhotoView.announceForAccessibility("Crime Scene Photo set");

Hi @cstewart,
I’m stuck trying to implement the 3rd challenge and appreciate some help.
I’m trying to make the call to View.announceForAccessibility in the onResume() method of and it is not working as expected.

Hi asett,

I guess the issue only occurs when the screen is in portrait and the reason is because of the usage of ViewPager.
As you know, ViewPager will create 3 fragments by default (the one you click in the list, the one in the left and the one in the right). All three onResume() methods of each fragment is called even you only click on one of them.
It’s fine to apps without voice. However, it will create an issue when the voice is needed.

I finished the task by referring the above solution. By the way, I put the announceForAccessibility() in the onActivityResult().

The code in is as follows.

    private boolean mIsVisibleToUser;

    public void setUserVisibleHint(boolean isVisibleToUser) {

        mIsVisibleToUser = isVisibleToUser;

    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode != Activity.RESULT_OK) {

        if ((requestCode == REQUEST_DATE) && (data != null)) {
            // ......
        } else if ((requestCode == REQUEST_CONTACT) && (data != null)) {
            // ......
        } else if (requestCode == REQUEST_PHOTO) {
            Uri targetUri = FileProvider.getUriForFile(getActivity(),
                    "", mPhotoFile);

            getActivity().revokeUriPermission(targetUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION);


    private void updatePhotoView() {
        if ((mPhotoFile == null) || !mPhotoFile.exists()) {
            // ......
            if (mIsVisibleToUser) {
        } else {
            // ......
            if (mIsVisibleToUser) {
1 Like

Thanks @crystalDf,
I will check this out and let you know how it goes