我需要知道在onResume
被调用至少一次之前是否会有onCreate
被调用的实例。感谢。
编辑:从活动生命周期来看,它似乎并非如此。但我想仔细检查。
答案 0 :(得分:106)
答案 1 :(得分:15)
onResume()
将始终被称为,但永远将在onCreate()
之前执行。
答案 2 :(得分:8)
答案 3 :(得分:5)
我遇到了一个问题,其中被覆盖的onCreate 不被调用。我尝试了调试和日志记录,我发现oncreate没有被调用。
原来我覆盖了错误的onCreate
@Override
public void onCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState) {
super.onCreate(savedInstanceState, persistentState);
}
这是正确的。
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
希望它可以帮助一些可怜的灵魂。 :)
因此在onResume
之前总会调用正确的onCreate()答案 4 :(得分:0)
活动有自己的生命周期。只需阅读并查看漂亮的图表:
http://developer.android.com/reference/android/app/Activity.html
onResume不会假设在onCreate之前运行,所以你假设正确。
答案 5 :(得分:0)
注意:此答案只需另外一个补充the accepted answers。
如先前的答案所说:
[10/05/2016 06:23:27 > 5c77b6: ERR ] Unhandled Exception: System.AggregateException: One or more errors occurred. (Unable to load DLL 'sni.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)) ---> System.DllNotFoundException: Unable to load DLL 'sni.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
[10/05/2016 06:23:27 > 5c77b6: ERR ] at System.Data.SqlClient.SNINativeMethodWrapper.UnmanagedIsTokenRestricted(IntPtr token, Boolean& isRestricted)
[10/05/2016 06:23:27 > 5c77b6: ERR ] at System.Data.Win32NativeMethods.IsTokenRestrictedWrapper(IntPtr token)
[10/05/2016 06:23:27 > 5c77b6: ERR ] at System.Data.ProviderBase.DbConnectionPoolIdentity.GetCurrent()
[10/05/2016 06:23:27 > 5c77b6: ERR ] at System.Data.ProviderBase.DbConnectionPoolGroup.GetConnectionPool(DbConnectionFactory connectionFactory)
[10/05/2016 06:23:27 > 5c77b6: ERR ] at System.Data.ProviderBase.DbConnectionFactory.GetConnectionPool(DbConnection owningObject, DbConnectionPoolGroup connectionPoolGroup)
[10/05/2016 06:23:27 > 5c77b6: ERR ] at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
[10/05/2016 06:23:27 > 5c77b6: ERR ] at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
[10/05/2016 06:23:27 > 5c77b6: ERR ] at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
[10/05/2016 06:23:27 > 5c77b6: ERR ] at System.Data.SqlClient.SqlConnection.Open()
[10/05/2016 06:23:27 > 5c77b6: ERR ] at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open()
[10/05/2016 06:23:27 > 5c77b6: ERR ] at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable.Enumerator.MoveNext()
[10/05/2016 06:23:27 > 5c77b6: ERR ] at Microsoft.EntityFrameworkCore.Query.QueryMethodProvider.<_ShapedQuery>d__3`1.MoveNext()
[10/05/2016 06:23:27 > 5c77b6: ERR ] at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.<_TrackEntities>d__15`2.MoveNext()
[10/05/2016 06:23:27 > 5c77b6: ERR ] at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.MoveNext()
[10/05/2016 06:23:27 > 5c77b6: ERR ] at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
[10/05/2016 06:23:27 > 5c77b6: ERR ] at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
[10/05/2016 06:23:27 > 5c77b6: ERR ] at CommerceVision.InteractivePurchasingModule.Workflow.DuplicateCheckWorkflowProcessor.<GetUnProcessedEmails>d__4.MoveNext()
[10/05/2016 06:23:27 > 5c77b6: ERR ] --- End of stack trace from previous location where exception was thrown ---
[10/05/2016 06:23:27 > 5c77b6: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
[10/05/2016 06:23:27 > 5c77b6: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[10/05/2016 06:23:27 > 5c77b6: ERR ] at CommerceVision.InteractivePurchasingModule.Workflow.DuplicateCheckWorkflowStep.<Process>d__7.MoveNext()
[10/05/2016 06:23:27 > 5c77b6: ERR ] --- End of stack trace from previous location where exception was thrown ---
[10/05/2016 06:23:27 > 5c77b6: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
[10/05/2016 06:23:27 > 5c77b6: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[10/05/2016 06:23:27 > 5c77b6: ERR ] at CommerceVision.InteractivePurchasingModule.Workflow.WorkflowEngine.<Execute>d__3.MoveNext()
[10/05/2016 06:23:27 > 5c77b6: ERR ] --- End of stack trace from previous location where exception was thrown ---
[10/05/2016 06:23:27 > 5c77b6: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
[10/05/2016 06:23:27 > 5c77b6: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[10/05/2016 06:23:27 > 5c77b6: ERR ] at CommerceVision.IpWorkflowProcessor.Program.<>c.<<ConfigureApplication>b__19_2>d.MoveNext()
[10/05/2016 06:23:27 > 5c77b6: ERR ] --- End of inner exception stack trace ---
[10/05/2016 06:23:27 > 5c77b6: ERR ] at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
[10/05/2016 06:23:27 > 5c77b6: ERR ] at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
[10/05/2016 06:23:27 > 5c77b6: ERR ] at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
[10/05/2016 06:23:27 > 5c77b6: ERR ] at CommerceVision.IpWorkflowProcessor.Program.Main(String[] args)
在Activity Lifecycle和Starting an Activity中了解详情。
来自android-lifecycle的活动生命周期的完整图片,包括片段生命周期: