gpt4 book ai didi

android - Activity 不启动

转载 作者:行者123 更新时间:2023-11-30 03:26:54 25 4
gpt4 key购买 nike

当我按下按钮开始新 Activity 时,应用程序转而进入主要 Activity 。
我真的很困惑,因为没有任何错误。我还在 On create of desired activity 中有日志消息 - 它不会弹出。你能告诉我是什么导致了这种奇怪的行为吗?

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

}

添加保存 Activity

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

Log cat 是空的 它只是显示,那个按钮被按下了。

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 中是 defiend

 <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 表单 Intent 移动到单例后,应用程序似乎可以正常工作

最佳答案

您不能使用应用程序上下文启动 Activity 。您只能使用另一个 Activity Context 启动它们。

以下更改应该可以解决此问题。将

替换为您的 Activity 名称
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

关于android - Activity 不启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18098252/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com