私は関数から別のクラスに総重量を渡そうとしました。私はgetIntent()を使用する予定です。しかし、静的関数はそれを許可しません。その場合、どうすればいいですか?以下はclass1の静的関数です。私は "this"の部分でエラーになっています。class1の静的関数から別のclass2に変数を渡すにはどうすればよいですか?
public class Shopping{
public static double getShipping(double total_weight) {
String weight = Double.toString(total_weight);
Intent intent = new Intent(this ,shopping1.class);
intent.putExtra(total_weights, weight);
this.startActivity(intent);
double shipping_fee = 0;
return shipping_fee;
}
}
これはクラス2の機能です。
public class shopping1 extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.shoppingcart);
Intent intent = getIntent();
String weight = intent.getStringExtra(Shopping.total_weights);
System.out.println(weight);
new connect5(this,
this.findViewById(android.R.id.content)).execute(weight);
}
}
STATIC関数は、クラス名を使用して直接呼び出すことができます –
呼び出す方法を表示できますか? –
関数を無効にして意図を呼び出す@CheongCharlene –