- Forum posts: 6
Jul 30, 2015, 9:37:46 PM via Website
Jul 30, 2015 9:37:46 PM via Website
I open images fullscreen from a productDetails activity. This new fullScreeActivity is working fine in the first try. Problem is happening when I press android native back button to return to productDetails and so try to open fullScreeActivity with the same image (just like if I´d like to see the image full again).
Logcat report:
07-30 18:51:10.294: E/AndroidRuntime(1866): FATAL EXCEPTION: main
07-30 18:51:10.294: E/AndroidRuntime(1866): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.habitodigital.handy/com.habitodigital.handy.FullScreenActivity}: java.lang.NullPointerException
07-30 18:51:10.294: E/AndroidRuntime(1866): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
07-30 18:51:10.294: E/AndroidRuntime(1866): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
07-30 18:51:10.294: E/AndroidRuntime(1866): at android.app.ActivityThread.access$600(ActivityThread.java:130)
07-30 18:51:10.294: E/AndroidRuntime(1866): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
07-30 18:51:10.294: E/AndroidRuntime(1866): at android.os.Handler.dispatchMessage(Handler.java:99)
07-30 18:51:10.294: E/AndroidRuntime(1866): at android.os.Looper.loop(Looper.java:137)
07-30 18:51:10.294: E/AndroidRuntime(1866): at android.app.ActivityThread.main(ActivityThread.java:4745)
07-30 18:51:10.294: E/AndroidRuntime(1866): at java.lang.reflect.Method.invokeNative(Native Method)
07-30 18:51:10.294: E/AndroidRuntime(1866): at java.lang.reflect.Method.invoke(Method.java:511)
07-30 18:51:10.294: E/AndroidRuntime(1866): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
07-30 18:51:10.294: E/AndroidRuntime(1866): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-30 18:51:10.294: E/AndroidRuntime(1866): at dalvik.system.NativeStart.main(Native Method)
07-30 18:51:10.294: E/AndroidRuntime(1866): Caused by: java.lang.NullPointerException
07-30 18:51:10.294: E/AndroidRuntime(1866): at com.habitodigital.handy.FullScreenActivity.createShareIntent(FullScreenActivity.java:99)
07-30 18:51:10.294: E/AndroidRuntime(1866): at com.habitodigital.handy.FullScreenActivity.access$0(FullScreenActivity.java:91)
07-30 18:51:10.294: E/AndroidRuntime(1866): at com.habitodigital.handy.FullScreenActivity$1.onSuccess(FullScreenActivity.java:74)
07-30 18:51:10.294: E/AndroidRuntime(1866): at com.squareup.picasso.RequestCreator.into(RequestCreator.java:514)
07-30 18:51:10.294: E/AndroidRuntime(1866): at com.habitodigital.handy.FullScreenActivity.onCreate(FullScreenActivity.java:66)
07-30 18:51:10.294: E/AndroidRuntime(1866): at android.app.Activity.performCreate(Activity.java:5008)
07-30 18:51:10.294: E/AndroidRuntime(1866): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
07-30 18:51:10.294: E/AndroidRuntime(1866): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
productDetails:
ImageView arquivo;
private static final String TAG_ARQUIVO = "arquivo";
String imagem;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_product_details);
DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
.showImageOnFail(R.drawable.no_image_available)
.showImageForEmptyUri(R.drawable.no_image_available)
.cacheInMemory(true)
.imageScaleType(ImageScaleType.EXACTLY)
.displayer(new FadeInBitmapDisplayer(300)).build();
arquivo = (ImageView) findViewById(R.id.arquivo);
Intent i = getIntent();
imagem = i.getStringExtra(TAG_ARQUIVO);
ImageLoader imageLoader = ImageLoader.getInstance();
imageLoader.displayImage(imagem, arquivo, defaultOptions);
arquivo.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent iFullImg = new Intent(getApplicationContext(), FullScreenActivity.class);
iFullImg.putExtra(TAG_ARQUIVO, imagem);
startActivity(iFullImg);
}
});
}
fullScreenActivity:
PhotoViewAttacher mAttacher;
private ShareActionProvider mShareActionProvider;
private static final String TAG_ARQUIVO = "arquivo";
String path;
File file;
ImageView fullImg;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_full_screen);
DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
.showImageOnFail(R.drawable.no_image_available)
.showImageForEmptyUri(R.drawable.no_image_available)
.cacheInMemory(true)
.imageScaleType(ImageScaleType.EXACTLY)
.displayer(new FadeInBitmapDisplayer(300)).build();
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
fullImg = (ImageView) findViewById(R.id.fullImage);
Intent i = getIntent();
path = i.getStringExtra(TAG_ARQUIVO);
ImageLoader imageLoader = ImageLoader.getInstance();
imageLoader.displayImage(path, fullImg, defaultOptions);
mAttacher = new PhotoViewAttacher(fullImg);
Picasso.with(this).load(path).into(fullImg, new Callback(){
@Override
public void onError() {
}
@Override
public void onSuccess() {
createShareIntent();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.full_screen, menu);
MenuItem item = menu.findItem(R.id.menu_item_share);
mShareActionProvider = (ShareActionProvider) item.getActionProvider();
return true;
}
private void createShareIntent() {
Uri bmpUri = getLocalBitmapUri(fullImg);
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
shareIntent.setType("image/*");
mShareActionProvider.setShareIntent(shareIntent);
}
// Returns the URI path to the Bitmap displayed in specified ImageView
public Uri getLocalBitmapUri(ImageView imageView) {
// Extract Bitmap from ImageView drawable
Drawable drawable = imageView.getDrawable();
Bitmap bmp = null;
if (drawable instanceof BitmapDrawable){
bmp = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
} else {
return null;
}
// Store image to default external storage directory
Uri bmpUri = null;
try {
File file = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_DOWNLOADS), "share_image_" + System.currentTimeMillis() + ".png");
file.getParentFile().mkdirs();
FileOutputStream out = new FileOutputStream(file);
bmp.compress(Bitmap.CompressFormat.PNG, 90, out);
out.close();
bmpUri = Uri.fromFile(file);
} catch (IOException e) {
e.printStackTrace();
}
return bmpUri;
}
When I remove createShareIntent() and Picasso codes it works fine. So I suppose it is what´s causing the problem. Any change I could do to make it work?
Recommended editorial content
With your consent, external content is loaded here.
By clicking on the button above, you agree that external content may be displayed to you. Personal data may be transmitted to third-party providers in the process. You can find more information about this in our Privacy Policy.