gpt4 book ai didi

android - 如何从应用程序模块调用库模块的 Activity

转载 作者:行者123 更新时间:2023-11-30 00:19:05 25 4
gpt4 key购买 nike

我想从应用程序模块调用库模块的Activity。但是应用程序崩溃了。以下是我的代码

主 Activity .java

public class MainActivity extends AppCompatActivity
{
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = new Intent("com.example.main.mainactivity");
startActivity(intent);
}
}

请帮助我。

最佳答案

The Intent constructor takes two parameters:

Intent intent = new Intent(Contecxt,Class);

1. A Context as its first parameter (this is used because the Activity class is a subclass of Context)

2. The Class of the app component to which the system should deliver the Intent (in this case, the activity that should be started).

read from docs

用这个

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

而不是这个

Intent intent = new Intent("com.example.main.mainactivity");
startActivity(intent);

关于android - 如何从应用程序模块调用库模块的 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46644464/

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