2017-10-09 24 views
0

我想打電話從應用module.but應用crash.following庫模塊的Activity是我的代碼如何從應用程序模塊調用庫模塊的活動

MainActivity.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); 
    } 
} 

請幫助我。

+1

份額的崩潰日誌與問題 –

+0

錯誤是顯而易見的...有行動沒有活動「com.example.main.mainactivity」... – Selvin

+0

活動是在圖書館或應用程序的清單中聲明的​​? –

回答

1

Intent構造有兩個參數:

Intent intent = new Intent(Contecxt,Class); 

1.甲上下文作爲它的第一個參數(這被使用,因爲活動類是背景信息的子類)

2.系統應傳遞給應用程序組件的類Inten t(在這種情況下,應該開始的活動)。

read from docs

使用本

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

,而不是這個

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

爲什麼它已經upvote? [這顯然甚至不會編譯](https://ideone.com/7e4x54)...這也不是真的:* Intent構造函數有兩個參數* .. Intent有多個構造函數 – Selvin

相關問題