2014-03-25 23 views
0

我的android應用程序使用JNI具有本機C代碼。 當應用程序被銷燬並重新啓動時,本地代碼的全局變量值仍然保持不變或未初始化。這個全局變量在其聲明點設置爲NULL,但其值與以前相同。Android活動已銷燬,但本機代碼全局變量的值仍然存在。爲什麼?

AVFormatContext *gFormatCtx = NULL; 

int openMovie(const char filePath[]) 
{ 
    if (gFormatCtx != NULL) // <- here, gFormatCtx is not null when the app is started at the second time. And its value is same as it was of first run. 
     return -1; 
} 

所以,我估計本機代碼的過程不會被殺死。這是爲什麼發生?

回答

1

活動不是您的應用程序進程。一個活動在不殺死其處理容器的情況下被銷燬是很常見的。這樣,您的全球流程狀態將保持不變。您應該對活動生命週期事件做出響應,以根據需要進行清理。

相關問題