1

当我按下按钮开始新活动时,应用程序转而进入主要活动。
我真的很困惑,因为没有任何错误。此外,我在创建所需活动时有日志消息 - 它不会弹出。你能告诉我什么会导致这种奇怪的行为吗?

    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();
        }

    }

添加保存活动

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.aadd_add_edit);
        Log.d("ATS", "was started");
                /*
                some job
                */
                }

日志猫是空的它只是shos,那个按钮被按下了。

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 在 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" />

有趣的事情 - 在 HTC phons 上始终可以正常工作,没有任何错误迹象。

编辑:在我将 imm 表单意图移动到单例后,应用程序似乎可以正常工作

4

3 回答 3

1

您无法使用应用程序上下文启动 Activity。您只能使用另一个活动上下文来启动它们。

以下更改应该可以解决此问题。将您的活动名称替换为 <YourCallingActivity>

Intent i = new Intent(<YourCallingActivity>.this, AddSaveActivity.class);

作为参考,以下是关于在哪个地方需要哪种上下文的指南:

http://www.doubleencore.com/2013/06/context/?utm_source=Android+Weekly&utm_campaign=78ad4cb95e-Android_Weekly_64&utm_medium=email&utm_term=0_4eb677ad19-78ad4cb95e-335181433

于 2013-08-07T08:50:24.957 回答
0

你可以试试:

            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);
于 2013-08-07T08:43:14.707 回答
0

这个问题是由字节数组强加的。Intent 不应该用于传输大量数据。在我将字节数组从意图转移到单例类之后,我不再遇到这个问题了。

于 2013-08-19T11:01:32.863 回答