Reputation: 4607
When i press button to start new activity, applications goes to main activity instead.
I am really confused because, there is no any error. Also I have log message in On create of desired activity - it does not pop up. Can you please tell me what can cause such strange behaviour?
public void btnAtcEdit(View v) {
Log.d("ATS", "i tried to go to ATS believe me");
try {
Log.d("ATS", " i tried to go to ATS 2 believe me");
// convert bitmap to bytearray to pass them in intent
final BitmapDrawable bitmapDrawable1 = (BitmapDrawable) photo1
.getDrawable();
final Bitmap yourBitmap1 = bitmapDrawable1.getBitmap();
ByteArrayOutputStream stream1 = new ByteArrayOutputStream();
yourBitmap1.compress(Bitmap.CompressFormat.PNG, 90, stream1);
byte[] imm1 = stream1.toByteArray();
final BitmapDrawable bitmapDrawable2 = (BitmapDrawable) photo2
.getDrawable();
final Bitmap yourBitmap2 = bitmapDrawable2.getBitmap();
ByteArrayOutputStream stream2 = new ByteArrayOutputStream();
yourBitmap2.compress(Bitmap.CompressFormat.PNG, 90, stream2);
byte[] imm2 = stream2.toByteArray();
final BitmapDrawable bitmapDrawable3 = (BitmapDrawable) photo3
.getDrawable();
final Bitmap yourBitmap3 = bitmapDrawable3.getBitmap();
ByteArrayOutputStream stream3 = new ByteArrayOutputStream();
yourBitmap3.compress(Bitmap.CompressFormat.PNG, 90, stream3);
byte[] imm3 = stream3.toByteArray();
Intent i = new Intent(AddToCheckActivity.this,
AddSaveActivity.class);
i.putExtra("photo1", imm1);
/*
putting more parameters
*/
i.putExtra("not_priceFor", not_priceFor);
startActivity(i);
stream1.flush();
stream1.close();
stream2.flush();
stream2.close();
stream3.flush();
stream3.close();
// finish();
} catch (Exception e) {
Log.d("ATS error", "before entered ATS");
e.printStackTrace();
}
}
AddSaveActivity
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.aadd_add_edit);
Log.d("ATS", "was started");
/*
some job
*/
}
Log cat is empty It just shos, that button was pressed.
08-07 11:32:28.250: D/ATS(19968): i tried to go to ATS believe me
08-07 11:32:28.250: D/ATS(19968): i tried to go to ATS 2 believe me
08-07 11:32:28.992: I/dalvikvm-heap(19968): Grow heap (frag case) to 22.075MB for 414640-byte allocation
08-07 11:32:29.054: D/dalvikvm(19968): GC_CONCURRENT freed 940K, 28% free 17454K/24111K, paused 15ms+3ms, total 59ms
08-07 11:32:29.187: E/Trace(20764): error opening trace file: No such file or directory (2)
08-07 11:32:29.203: V/ActivityThread(20764): Class path: /system/framework/com.google.android.maps.jar:/data/app/ua.mirkvartir.android.frontend-2.apk, JNI path: /data/data/ua.mirkvartir.android.frontend/lib
08-07 11:32:29.398: D/dalvikvm(20764): GC_CONCURRENT freed 89K, 22% free 9913K/12651K, paused 14ms+2ms, total 38ms
08-07 11:32:29.398: D/dalvikvm(20764): WAIT_FOR_CONCURRENT_GC blocked 10ms
08-07 11:32:29.414: D/login(20764): -- 0
08-07 11:32:29.468: D/libEGL(20764): loaded /vendor/lib/egl/libEGL_POWERVR_SGX540_120.so
08-07 11:32:29.492: D/libEGL(20764): loaded /vendor/lib/egl/libGLESv1_CM_POWERVR_SGX540_120.so
08-07 11:32:29.492: D/libEGL(20764): loaded /vendor/lib/egl/libGLESv2_POWERVR_SGX540_120.so
08-07 11:32:29.656: D/OpenGLRenderer(20764): Enabling debug mode 0
onClickListener for button is defiend in xml
<Button
android:id="@+id/btnAtcEdic"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_margin="0dp"
android:layout_marginBottom="10sp"
android:layout_marginLeft="40sp"
android:layout_marginRight="40sp"
android:layout_marginTop="10sp"
android:layout_weight="1"
android:background="@drawable/button_primary"
android:drawablePadding="0sp"
android:onClick="btnAtcEdit"
android:padding="0dp"
android:text="Редактировать"
android:textColor="#FFFFFF" />
Interesting thing - always works without any sign of error on HTC phons.
EDIT: after i moved imm form intent to singleton, app seems to work properly
Upvotes: 1
Views: 133
Reputation: 4607
The problem was imposed by bytearrays. Intent is not suppossed to be used to transmit large ammount of data. After I moved bytearrays from intent to singleton class I have not had that problem any more.
Upvotes: 0
Reputation: 19280
You can't start an Activity using the Application Context. You can only start them with another Activity Context.
The following change should fix this. Substitute your Activity name for <YourCallingActivity>
Intent i = new Intent(<YourCallingActivity>.this, AddSaveActivity.class);
For reference, here is a guide on which kind of context is needed in which place:
Upvotes: 1
Reputation: 7415
U can try:
stream1.flush();
stream1.close();
stream2.flush();
stream2.close();
stream3.flush();
stream3.close();
Intent i = new Intent(SecondActivity.this,
AddSaveActivity.class);
i.putExtra("photo1", imm1);
/*
putting more parameters
*/
i.putExtra("not_priceFor", not_priceFor);
startActivity(i);
Upvotes: 0