所需的流程不需要广播和接收器设置。由于将
ChooseNumber1
Activity在
Service完成工作之后启动,因此您只需要将附加
ArrayList到
Intent用于启动上即可
ChooseNumber1。然后可以在中检索该列表
onCreate(),并且可以立即初始化your
ListView及其列表
Adapter,而不必尝试等待广播。
例如,在
Service清单中,您的中的清单被组合后:
Intent mobileNumbersIntent = new Intent(this, ChooseNumber1.class);mobileNumbersIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);mobileNumbersIntent.putStringArrayListExtra("mobileNumbers", mobileNumberList);startActivity(mobileNumbersIntent);
然后,在
Activity:
public class ChooseNumber1 extends AppCompatActivity { private ArrayAdapter<String> mobileNumberAdapter; private ArrayList<String> mobileNumbersList = new ArrayList<>(); private ListView mobileNumberListView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_choose_number1); ... mobileNumberListView = (ListView) findViewById(R.id.listViewNumberList); mobileNumbersList = getIntent().getStringArrayListExtra("mobileNumbers"); if(mobileNumbersList != null) { mobileNumberAdapter = new ArrayAdapter<String>(this, R.layout.list_item_numbers, R.id.list_item_number_textview, mobileNumbersList); mobileNumberListView.setAdapter(mobileNumberAdapter); } }}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)