Search code examples
androidandroid-activitymirah

OnActivityResult not triggered on finish


The following application works as expected:

import android.app.Activity
import android.content.Intent
import android.graphics.BitmapFactory
import android.app.WallpaperManager

class ChwallActivity < Activity
  def onCreate(state)
    super
    setContentView R.layout.main
  end

  $Override
  def onStart
    super
    Intent intent = Intent.new(Intent.ACTION_PICK)
    intent.setType "image/*"
    startActivityForResult Intent.createChooser(intent, "Select Picture"), 0
  end

  $Override
  def onActivityResult(requestCode, resultCode, data:Intent)
    super
    thumb = BitmapFactory.decodeFile "/storage/sdcard0/download/foo.jpg"
    manager = WallpaperManager.getInstance self
    manager.setBitmap thumb
  end
end

This executes a gallery-picker in an infinite loop, which is undesirable. However, if I insert a finish at the end of the onStart() function, onActivityResult() doesn't seem to be called: the wallpaper doesn't change to foo.jpg. Is onActivityResult() being called when the gallery starts up the second time? What is going on?


Solution

  • Putting the finish in onActivityResult() works.