2017-11-08 2 views
0

총 3 개의 활동이 있습니다. 1. 활동에는 기록 및 입력이 포함됩니다. 2. 활동, QRCode 스캔 및 리턴 데이터 활동 3은 활동 2에서 데이터를 수신합니다.QRcode를 읽은 후 활동이 잠김

스크립트는 다음과 같습니다. 로그인 한 후 사용자 ID로 qrcode를 읽을 수 있습니다. 읽은 후 Intent.PutExtra를 사용하여 관련 데이터를 세 번째 활동으로 보내려고합니다.

문제 :

QRCode의이 읽기 전에 제 3 활동을 열 수 있지만, 제 3 활동이 독서 후 열고 오류를 제공하지 않습니다. 다른 버튼에서도 기능이 저하됩니다.

프로그램을 연속적으로 처리하려면 프로그램을 다시 컴파일해야합니다.

QRCode 스캐닝에 Zxing 라이브러리를 사용합니다.

기타 문제 : QRCode의를 읽은 후, 그것은 내가 문제가 무엇인지 이해하지 못하는 활동 2.

로 이동하지 않고 활동 1로 이동합니다. 내 코드의

모든 :

ActivityUserProfile

<?xml version="1.0" encoding="utf-8"?> 
    <RelativeLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     tools:context="com.example.batuhan.qrcodereader.ActivityUserProfile" 
     android:paddingLeft="16dp" 
     android:paddingRight="16dp" 
     android:paddingTop="16dp" 
     android:paddingBottom="16dp"> 

</Relativelayout> 

ActivityUserProfile.class

public class ActivityUserProfile extends AppCompatActivity { 


private ZXingScannerView scannerView; 


public static final String LOGIN_URL = "http://www.HHH.com/QR_Users_Select.php"; 

public static final String KEY_USERNAME = "username"; 
public static final String KEY_PASSWORD = "password"; 


private TextView txt_ViewUsername; 
public static EditText edt_Productname; 
public static EditText edt_Productcode; 
public static EditText edt_Productweight; 
public static EditText edt_Productprice; 

private Button btn_addToCart; 
private Button btn_Scan; 
private Button btn_seeProd; 

String resultCode; 

public String prodName; 
public String prodCode; 
public String prodWeight; 
public String prodPrice; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_user_profile); 

    txt_ViewUsername = (TextView) findViewById(R.id.txt_ViewUsername); 
    edt_Productname = (EditText) findViewById(R.id.edt_ProdName); 
    edt_Productcode = (EditText) findViewById(R.id.edt_ProdCode); 
    edt_Productweight= (EditText) findViewById(R.id.edt_ProdWeight); 
    edt_Productprice = (EditText) findViewById(R.id.edt_ProdPrice); 

    edt_Productcode.setEnabled(true); 
    edt_Productname.setEnabled(true); 
    edt_Productweight.setEnabled(true); 
    edt_Productprice.setEnabled(true); 

    Intent i = getIntent(); 
    txt_ViewUsername.setText("Sayın "+ i.getStringExtra(ActivityUserProfile.KEY_USERNAME) +" marketimize hoşgeldiniz."); 



    btn_Scan = (Button) findViewById(R.id.btn_scan); 
    btn_Scan.setOnClickListener(new OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      scanCode(); 

     } 
    }); 


    btn_seeProd = (Button) findViewById(R.id.btn_seeProd); 
    btn_seeProd.setOnClickListener(new OnClickListener() { 
     @Override 
     public void onClick(View v) { 

      Intent intent = new Intent(getApplicationContext(),ProductView.class); 
      startActivity(intent); 
     } 
    }); 




    btn_addToCart = (Button) findViewById(R.id.btn_addToCart); 
    btn_addToCart.setOnClickListener(new OnClickListener() { 
     @Override 
     public void onClick(View v) { 

      ... 
     } 
    }); 
} 

public void scanCode() 
{ 
    scannerView = new ZXingScannerView(this); 
    scannerView.setResultHandler(new ZXingScannerResultHandler()); 

    setContentView(scannerView); 
    scannerView.startCamera(); 

} 
@Override 
public void onPause(){ 
    super.onPause(); 


    if (scannerView != null) { 
     scannerView.stopCamera(); 
     scannerView = null; 
    } 


} 



public class ZXingScannerResultHandler implements ZXingScannerView.ResultHandler 
{ 
    @Override 
    public void handleResult(Result result){ 
     try{ 

      resultCode = result.getText(); 
      Log.i("Bilgi","ResultCode -> "+resultCode); 
      setContentView(R.layout.activity_user_profile); 
      scannerView.removeAllViews(); 
      scannerView.stopCamera(); 

      String [] chars = resultCode.split(":"); 
      Log.i("counter",chars.length+""); 
      Log.i("company",chars[1]); 

      prodName = chars[1]; 
      prodCode = chars[3]; 
      prodWeight =chars[5]; 
      prodPrice = chars[7]; 



      EditText product_name_text = (EditText) findViewById(R.id.edt_ProdName); 
      EditText product_code_text = (EditText) findViewById(R.id.edt_ProdCode); 
      EditText product_weight_text= (EditText) findViewById(R.id.edt_ProdWeight); 
      EditText product_price_text = (EditText) findViewById(R.id.edt_ProdPrice); 

      product_name_text.setText(prodName); 
      product_code_text.setText(prodCode); 
      product_weight_text.setText(String.valueOf(prodWeight)); 
      product_price_text.setText(String.valueOf(prodPrice)); 

     } catch (NullPointerException nu) { 
      Toast.makeText(ActivityUserProfile.this,"Gelen data düzenli değil!",Toast.LENGTH_LONG).show(); 
     } catch (Exception ex){ 
      Toast.makeText(ActivityUserProfile.this,"Okuyucuda problem oluştu!",Toast.LENGTH_LONG).show(); 
      Log.e("errors",ex.getMessage()); 
     } 
    } 
} 

답변

0

ApplicaitonContext는 일없이 스택에 활동을 추가하기에 적합하지 않습니다 e NEW_TASK 플래그이므로 다음을 수행하십시오.

Intent intent = new Intent(ActivityUserProfile.this, ProductView.class); 
    startActivity(intent); 

이름이 View 임에도 불구하고 ProductView가 활동 인 것으로 가정합니다. (startActivity를하기 전에) 그 의도에 갈 것

귀하의 추가 데이터는 수행

intent.putExtra("PROD_ID", edit_Productcode.getText().toString); 

을 그 다음 ProductView의 활동에 :

String prodCode = getIntent().getStringExtra("PROD_ID"); 

귀하의 handleResult은 활동의 내용 없음이 작업하려고 대체 할 이미 가지고있는 인스턴스가 있거나 화면을 변경해야하는 경우 조각을 사용하십시오.

당신의 activty는 첫 번째 contentView에 리스너가 있었기 때문에 열리지 않습니다. setContentView (R.layout.activity_user_profile);를 사용하고 있습니다. handleResult에서이 줄을 제거하면됩니다.

참고 : 변수 이름에 밑줄이 필요하지 않으므로 edit_Productcode 대신 editProductCode를 호출 할 수 있습니다 (낙타의 경우도 마찬가지 임)

관련 문제