概述活动将发送和整数到培训活动,培训活动将在活动从堆栈中弹出时向其调用者发送反馈。所以当它返回一个整数到概述活动时,logcat会说错误。资源未找到
这是OverviewActivity Class
package com.ehsan.myapplication;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
public class OverviewActivity extends AppCompatActivity {
String text = null;
int skillLevle = 0;
public static final int REQUEST_CODE = 0;
private TextView mTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_overview);
Intent intent = getIntent();
Bundle bundle = intent.getExtras();
mTextView = (TextView) findViewById(R.id.username);
if(intent != null){
text = bundle.getString("username");
mTextView.setText(text);
}
}
public void onClick(View view){
Intent intent = new Intent(this,LearnActivity.class);
intent.putExtra("skill",skillLevle);
startActivityForResult(intent,REQUEST_CODE);
}
public void onActivityResult(int reqeuestCode,int resutlCode,Intent extras){
int skills = extras.getIntExtra("skill",0);
Toast.makeText(this, skills, Toast.LENGTH_LONG).show();
}
}
这是LearnActivity Class
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class LearnActivity extends AppCompatActivity {
private int skillLevle = 5;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_learn);
Intent intent = getIntent();
if (intent != null){
skillLevle = intent.getExtras().getInt("skill");
}
}
public void finish(){
Intent intent2 = new Intent();
intent2.putExtra("skill",skillLevle);
setResult(RESULT_OK,intent2);
super.finish();
}
}